]> granicus.if.org Git - postgresql/commitdiff
Refactor sprintf calls with computed format strings into multiple calls with
authorPeter Eisentraut <peter_e@gmx.net>
Wed, 16 Jun 2010 00:54:16 +0000 (00:54 +0000)
committerPeter Eisentraut <peter_e@gmx.net>
Wed, 16 Jun 2010 00:54:16 +0000 (00:54 +0000)
constant format strings, so that the compiler can more easily check the
formats for correctness.

src/backend/postmaster/postmaster.c
src/interfaces/ecpg/pgtypeslib/dt_common.c

index 0a3064753d38f4d92de0ad98273adf37eb9ba0df..eba940cf428eee5f33355e3bcad20853ee8974b8 100644 (file)
@@ -37,7 +37,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.611 2010/06/03 21:02:11 petere Exp $
+ *       $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.612 2010/06/16 00:54:16 petere Exp $
  *
  * NOTES
  *
@@ -3381,9 +3381,10 @@ BackendInitialize(Port *port)
                                        (errmsg_internal("pg_getnameinfo_all() failed: %s",
                                                                         gai_strerror(ret))));
        }
-       snprintf(remote_ps_data, sizeof(remote_ps_data),
-                        remote_port[0] == '\0' ? "%s" : "%s(%s)",
-                        remote_host, remote_port);
+       if (remote_port[0] == '\0')
+               snprintf(remote_ps_data, sizeof(remote_ps_data), "%s", remote_host);
+       else
+               snprintf(remote_ps_data, sizeof(remote_ps_data), "%s(%s)", remote_host, remote_port);
 
        if (Log_connections)
        {
index 52bb5d2ca170a92d5d37f504711de621b06bd1db..dc430f7881f975e46c2778a45ca291bb1b61211f 100644 (file)
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.53 2010/05/09 02:15:59 tgl Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.54 2010/06/16 00:54:16 petere Exp $ */
 
 #include "postgres_fe.h"
 
@@ -815,7 +815,10 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
                        {
                                hour = -(*tzp / SECS_PER_HOUR);
                                min = (abs(*tzp) / MINS_PER_HOUR) % MINS_PER_HOUR;
-                               sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
+                               if (min != 0)
+                                       sprintf(str + strlen(str), "%+03d:%02d", hour, min);
+                               else
+                                       sprintf(str + strlen(str), "%+03d", hour);
                        }
                        break;
 
@@ -869,7 +872,10 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
                                {
                                        hour = -(*tzp / SECS_PER_HOUR);
                                        min = (abs(*tzp) / MINS_PER_HOUR) % MINS_PER_HOUR;
-                                       sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
+                                       if (min != 0)
+                                               sprintf(str + strlen(str), "%+03d:%02d", hour, min);
+                                       else
+                                               sprintf(str + strlen(str), "%+03d", hour);
                                }
                        }
                        break;
@@ -915,7 +921,10 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
                                {
                                        hour = -(*tzp / SECS_PER_HOUR);
                                        min = (abs(*tzp) / MINS_PER_HOUR) % MINS_PER_HOUR;
-                                       sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
+                                       if (min != 0)
+                                               sprintf(str + strlen(str), "%+03d:%02d", hour, min);
+                                       else
+                                               sprintf(str + strlen(str), "%+03d", hour);
                                }
                        }
                        break;
@@ -977,7 +986,10 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
                                         */
                                        hour = -(*tzp / SECS_PER_HOUR);
                                        min = (abs(*tzp) / MINS_PER_HOUR) % MINS_PER_HOUR;
-                                       sprintf(str + strlen(str), (min != 0) ? " %+03d:%02d" : " %+03d", hour, min);
+                                       if (min != 0)
+                                               sprintf(str + strlen(str), " %+03d:%02d", hour, min);
+                                       else
+                                               sprintf(str + strlen(str), " %+03d", hour);
                                }
                        }
                        break;