Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit418e1d8

Browse files
committed
Refactor sprintf calls with computed format strings into multiple calls with
constant format strings, so that the compiler can more easily check theformats for correctness.
1 parent24cb6ab commit418e1d8

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.611 2010/06/03 21:02:11 petere Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.612 2010/06/16 00:54:16 petere Exp $
4141
*
4242
* NOTES
4343
*
@@ -3381,9 +3381,10 @@ BackendInitialize(Port *port)
33813381
(errmsg_internal("pg_getnameinfo_all() failed: %s",
33823382
gai_strerror(ret))));
33833383
}
3384-
snprintf(remote_ps_data,sizeof(remote_ps_data),
3385-
remote_port[0]=='\0' ?"%s" :"%s(%s)",
3386-
remote_host,remote_port);
3384+
if (remote_port[0]=='\0')
3385+
snprintf(remote_ps_data,sizeof(remote_ps_data),"%s",remote_host);
3386+
else
3387+
snprintf(remote_ps_data,sizeof(remote_ps_data),"%s(%s)",remote_host,remote_port);
33873388

33883389
if (Log_connections)
33893390
{

‎src/interfaces/ecpg/pgtypeslib/dt_common.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.53 2010/05/09 02:15:59 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.54 2010/06/16 00:54:16 petere Exp $ */
22

33
#include"postgres_fe.h"
44

@@ -815,7 +815,10 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
815815
{
816816
hour=-(*tzp /SECS_PER_HOUR);
817817
min= (abs(*tzp) /MINS_PER_HOUR) %MINS_PER_HOUR;
818-
sprintf(str+strlen(str), (min!=0) ?"%+03d:%02d" :"%+03d",hour,min);
818+
if (min!=0)
819+
sprintf(str+strlen(str),"%+03d:%02d",hour,min);
820+
else
821+
sprintf(str+strlen(str),"%+03d",hour);
819822
}
820823
break;
821824

@@ -869,7 +872,10 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
869872
{
870873
hour=-(*tzp /SECS_PER_HOUR);
871874
min= (abs(*tzp) /MINS_PER_HOUR) %MINS_PER_HOUR;
872-
sprintf(str+strlen(str), (min!=0) ?"%+03d:%02d" :"%+03d",hour,min);
875+
if (min!=0)
876+
sprintf(str+strlen(str),"%+03d:%02d",hour,min);
877+
else
878+
sprintf(str+strlen(str),"%+03d",hour);
873879
}
874880
}
875881
break;
@@ -915,7 +921,10 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
915921
{
916922
hour=-(*tzp /SECS_PER_HOUR);
917923
min= (abs(*tzp) /MINS_PER_HOUR) %MINS_PER_HOUR;
918-
sprintf(str+strlen(str), (min!=0) ?"%+03d:%02d" :"%+03d",hour,min);
924+
if (min!=0)
925+
sprintf(str+strlen(str),"%+03d:%02d",hour,min);
926+
else
927+
sprintf(str+strlen(str),"%+03d",hour);
919928
}
920929
}
921930
break;
@@ -977,7 +986,10 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
977986
*/
978987
hour=-(*tzp /SECS_PER_HOUR);
979988
min= (abs(*tzp) /MINS_PER_HOUR) %MINS_PER_HOUR;
980-
sprintf(str+strlen(str), (min!=0) ?" %+03d:%02d" :" %+03d",hour,min);
989+
if (min!=0)
990+
sprintf(str+strlen(str)," %+03d:%02d",hour,min);
991+
else
992+
sprintf(str+strlen(str)," %+03d",hour);
981993
}
982994
}
983995
break;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp