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

Commitcbd8913

Browse files
committed
Remove unportable assumption that it's okay to use the target buffer
of an sprintf() as a source string. Demonstrably does not work withrecent gcc and/or glibc on some platforms.
1 parent40f32f3 commitcbd8913

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

‎src/backend/utils/adt/formatting.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* -----------------------------------------------------------------------
22
* formatting.c
33
*
4-
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.83 2005/01/01 05:43:07 momjian Exp $
4+
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.84 2005/01/13 01:40:13 tgl Exp $
55
*
66
*
77
* Portions Copyright (c) 1999-2005, PostgreSQL Global Development Group
@@ -1462,7 +1462,9 @@ get_th(char *num, int type)
14621462
staticchar*
14631463
str_numth(char*dest,char*num,inttype)
14641464
{
1465-
sprintf(dest,"%s%s",num,get_th(num,type));
1465+
if (dest!=num)
1466+
strcpy(dest,num);
1467+
strcat(dest,get_th(num,type));
14661468
returndest;
14671469
}
14681470

@@ -2057,6 +2059,7 @@ static int
20572059
dch_date(intarg,char*inout,intsuf,intflag,FormatNode*node,void*data)
20582060
{
20592061
charbuff[DCH_CACHE_SIZE],
2062+
workbuff[32],
20602063
*p_inout;
20612064
inti,
20622065
len;
@@ -2117,7 +2120,6 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
21172120

21182121
switch (arg)
21192122
{
2120-
21212123
caseDCH_A_D:
21222124
caseDCH_B_C:
21232125
if (flag==TO_CHAR)
@@ -2179,8 +2181,8 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
21792181
}
21802182
break;
21812183
caseDCH_MONTH:
2182-
strcpy(inout,months_full[tm->tm_mon-1]);
2183-
sprintf(inout,"%*s",S_FM(suf) ?0 :-9,str_toupper(inout));
2184+
strcpy(workbuff,months_full[tm->tm_mon-1]);
2185+
sprintf(inout,"%*s",S_FM(suf) ?0 :-9,str_toupper(workbuff));
21842186
if (S_FM(suf))
21852187
returnstrlen(p_inout)-1;
21862188
else
@@ -2242,8 +2244,8 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
22422244
}
22432245
break;
22442246
caseDCH_DAY:
2245-
strcpy(inout,days[tm->tm_wday]);
2246-
sprintf(inout,"%*s",S_FM(suf) ?0 :-9,str_toupper(inout));
2247+
strcpy(workbuff,days[tm->tm_wday]);
2248+
sprintf(inout,"%*s",S_FM(suf) ?0 :-9,str_toupper(workbuff));
22472249
if (S_FM(suf))
22482250
returnstrlen(p_inout)-1;
22492251
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp