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

Commit3a4b891

Browse files
committed
Fix more format truncation issues
Fix the warnings created by the compiler warning options-Wformat-overflow=2 -Wformat-truncation=2, supported since GCC 7. Thisis a more aggressive variant of the fixes in6275f5d, which GCC 7 warned about bydefault.The issues are all harmless, but some dubious coding patterns arecleaned up.One issue that is of external interest is that BGW_MAXLEN is increasedfrom 64 to 96. Apparently, the old value would cause the bgw_name oflogical replication workers to be truncated in some circumstances.But this doesn't actually add those warning options. It appears thatthe warnings depend a bit on compilation and optimization options, so itwould be annoying to have to keep up with that. This is more of aonce-in-a-while cleanup.Reviewed-by: Michael Paquier <michael@paquier.xyz>
1 parent648a6c7 commit3a4b891

File tree

14 files changed

+38
-54
lines changed

14 files changed

+38
-54
lines changed

‎contrib/pgstattuple/pgstattuple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static Datum
8989
build_pgstattuple_type(pgstattuple_type*stat,FunctionCallInfofcinfo)
9090
{
9191
#defineNCOLUMNS9
92-
#defineNCHARS32
92+
#defineNCHARS314
9393

9494
HeapTupletuple;
9595
char*values[NCOLUMNS];

‎src/backend/commands/explain.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,10 +3337,11 @@ void
33373337
ExplainPropertyFloat(constchar*qlabel,doublevalue,intndigits,
33383338
ExplainState*es)
33393339
{
3340-
charbuf[256];
3340+
char*buf;
33413341

3342-
snprintf(buf,sizeof(buf),"%.*f",ndigits,value);
3342+
buf=psprintf("%.*f",ndigits,value);
33433343
ExplainProperty(qlabel,buf, true,es);
3344+
pfree(buf);
33443345
}
33453346

33463347
/*

‎src/backend/libpq/be-secure-openssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ static const char *
10131013
SSLerrmessage(unsigned longecode)
10141014
{
10151015
constchar*errreason;
1016-
staticcharerrbuf[32];
1016+
staticcharerrbuf[36];
10171017

10181018
if (ecode==0)
10191019
return_("no SSL error reported");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ calculate_database_size(Oid dbOid)
8686
DIR*dirdesc;
8787
structdirent*direntry;
8888
chardirpath[MAXPGPATH];
89-
charpathname[MAXPGPATH+12+sizeof(TABLESPACE_VERSION_DIRECTORY)];
89+
charpathname[MAXPGPATH+21+sizeof(TABLESPACE_VERSION_DIRECTORY)];
9090
AclResultaclresult;
9191

9292
/*

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ static const uint32 nan[2] = {0xffffffff, 0x7fffffff};
4444
#defineNAN (*(const double *) nan)
4545
#endif
4646

47-
/* not sure what the following should be, but better to make it over-sufficient */
48-
#defineMAXFLOATWIDTH64
49-
#defineMAXDOUBLEWIDTH128
50-
5147
/*
5248
* check to see if a float4/8 val has underflowed or overflowed
5349
*/
@@ -360,18 +356,18 @@ Datum
360356
float4out(PG_FUNCTION_ARGS)
361357
{
362358
float4num=PG_GETARG_FLOAT4(0);
363-
char*ascii= (char*)palloc(MAXFLOATWIDTH+1);
359+
char*ascii;
364360

365361
if (isnan(num))
366-
PG_RETURN_CSTRING(strcpy(ascii,"NaN"));
362+
PG_RETURN_CSTRING(pstrdup("NaN"));
367363

368364
switch (is_infinite(num))
369365
{
370366
case1:
371-
strcpy(ascii,"Infinity");
367+
ascii=pstrdup("Infinity");
372368
break;
373369
case-1:
374-
strcpy(ascii,"-Infinity");
370+
ascii=pstrdup("-Infinity");
375371
break;
376372
default:
377373
{
@@ -380,7 +376,7 @@ float4out(PG_FUNCTION_ARGS)
380376
if (ndig<1)
381377
ndig=1;
382378

383-
snprintf(ascii,MAXFLOATWIDTH+1,"%.*g",ndig,num);
379+
ascii=psprintf("%.*g",ndig,num);
384380
}
385381
}
386382

@@ -596,18 +592,18 @@ float8out(PG_FUNCTION_ARGS)
596592
char*
597593
float8out_internal(doublenum)
598594
{
599-
char*ascii= (char*)palloc(MAXDOUBLEWIDTH+1);
595+
char*ascii;
600596

601597
if (isnan(num))
602-
returnstrcpy(ascii,"NaN");
598+
returnpstrdup("NaN");
603599

604600
switch (is_infinite(num))
605601
{
606602
case1:
607-
strcpy(ascii,"Infinity");
603+
ascii=pstrdup("Infinity");
608604
break;
609605
case-1:
610-
strcpy(ascii,"-Infinity");
606+
ascii=pstrdup("-Infinity");
611607
break;
612608
default:
613609
{
@@ -616,7 +612,7 @@ float8out_internal(double num)
616612
if (ndig<1)
617613
ndig=1;
618614

619-
snprintf(ascii,MAXDOUBLEWIDTH+1,"%.*g",ndig,num);
615+
ascii=psprintf("%.*g",ndig,num);
620616
}
621617
}
622618

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

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,6 @@
117117
#defineDCH_MAX_ITEM_SIZ 12/* max localized day name*/
118118
#defineNUM_MAX_ITEM_SIZ8/* roman number (RN has 15 chars)*/
119119

120-
/* ----------
121-
* More is in float.c
122-
* ----------
123-
*/
124-
#defineMAXFLOATWIDTH60
125-
#defineMAXDOUBLEWIDTH500
126-
127120

128121
/* ----------
129122
* Format parser structs
@@ -3911,9 +3904,7 @@ do_to_timestamp(text *date_txt, text *fmt,
39113904
tmfc.tzm<0||tmfc.tzm >=MINS_PER_HOUR)
39123905
DateTimeParseError(DTERR_TZDISP_OVERFLOW,date_str,"timestamp");
39133906

3914-
tz=palloc(7);
3915-
3916-
snprintf(tz,7,"%c%02d:%02d",
3907+
tz=psprintf("%c%02d:%02d",
39173908
tmfc.tzsign>0 ?'+' :'-',tmfc.tzh,tmfc.tzm);
39183909

39193910
tm->tm_zone=tz;
@@ -4135,7 +4126,7 @@ int_to_roman(int number)
41354126
num=0;
41364127
char*p=NULL,
41374128
*result,
4138-
numstr[5];
4129+
numstr[12];
41394130

41404131
result= (char*)palloc(16);
41414132
*result='\0';
@@ -5441,8 +5432,7 @@ int4_to_char(PG_FUNCTION_ARGS)
54415432
/* we can do it easily because float8 won't lose any precision */
54425433
float8val= (float8)value;
54435434

5444-
orgnum= (char*)palloc(MAXDOUBLEWIDTH+1);
5445-
snprintf(orgnum,MAXDOUBLEWIDTH+1,"%+.*e",Num.post,val);
5435+
orgnum= (char*)psprintf("%+.*e",Num.post,val);
54465436

54475437
/*
54485438
* Swap a leading positive sign for a space.
@@ -5641,7 +5631,6 @@ float4_to_char(PG_FUNCTION_ARGS)
56415631
numstr=orgnum=int_to_roman((int)rint(value));
56425632
elseif (IS_EEEE(&Num))
56435633
{
5644-
numstr=orgnum= (char*)palloc(MAXDOUBLEWIDTH+1);
56455634
if (isnan(value)||is_infinite(value))
56465635
{
56475636
/*
@@ -5655,7 +5644,7 @@ float4_to_char(PG_FUNCTION_ARGS)
56555644
}
56565645
else
56575646
{
5658-
snprintf(orgnum,MAXDOUBLEWIDTH+1,"%+.*e",Num.post,value);
5647+
numstr=orgnum=psprintf("%+.*e",Num.post,value);
56595648

56605649
/*
56615650
* Swap a leading positive sign for a space.
@@ -5679,16 +5668,15 @@ float4_to_char(PG_FUNCTION_ARGS)
56795668
Num.pre+=Num.multi;
56805669
}
56815670

5682-
orgnum= (char*)palloc(MAXFLOATWIDTH+1);
5683-
snprintf(orgnum,MAXFLOATWIDTH+1,"%.0f",fabs(val));
5671+
orgnum= (char*)psprintf("%.0f",fabs(val));
56845672
numstr_pre_len=strlen(orgnum);
56855673

56865674
/* adjust post digits to fit max float digits */
56875675
if (numstr_pre_len >=FLT_DIG)
56885676
Num.post=0;
56895677
elseif (numstr_pre_len+Num.post>FLT_DIG)
56905678
Num.post=FLT_DIG-numstr_pre_len;
5691-
snprintf(orgnum,MAXFLOATWIDTH+1,"%.*f",Num.post,val);
5679+
orgnum=psprintf("%.*f",Num.post,val);
56925680

56935681
if (*orgnum=='-')
56945682
{/* < 0 */
@@ -5747,7 +5735,6 @@ float8_to_char(PG_FUNCTION_ARGS)
57475735
numstr=orgnum=int_to_roman((int)rint(value));
57485736
elseif (IS_EEEE(&Num))
57495737
{
5750-
numstr=orgnum= (char*)palloc(MAXDOUBLEWIDTH+1);
57515738
if (isnan(value)||is_infinite(value))
57525739
{
57535740
/*
@@ -5761,7 +5748,7 @@ float8_to_char(PG_FUNCTION_ARGS)
57615748
}
57625749
else
57635750
{
5764-
snprintf(orgnum,MAXDOUBLEWIDTH+1,"%+.*e",Num.post,value);
5751+
numstr=orgnum= (char*)psprintf("%+.*e",Num.post,value);
57655752

57665753
/*
57675754
* Swap a leading positive sign for a space.
@@ -5784,15 +5771,15 @@ float8_to_char(PG_FUNCTION_ARGS)
57845771
val=value*multi;
57855772
Num.pre+=Num.multi;
57865773
}
5787-
orgnum=(char*)palloc(MAXDOUBLEWIDTH+1);
5788-
numstr_pre_len=snprintf(orgnum,MAXDOUBLEWIDTH+1,"%.0f",fabs(val));
5774+
orgnum=psprintf("%.0f",fabs(val));
5775+
numstr_pre_len=strlen(orgnum);
57895776

57905777
/* adjust post digits to fit max double digits */
57915778
if (numstr_pre_len >=DBL_DIG)
57925779
Num.post=0;
57935780
elseif (numstr_pre_len+Num.post>DBL_DIG)
57945781
Num.post=DBL_DIG-numstr_pre_len;
5795-
snprintf(orgnum,MAXDOUBLEWIDTH+1,"%.*f",Num.post,val);
5782+
orgnum=psprintf("%.*f",Num.post,val);
57965783

57975784
if (*orgnum=='-')
57985785
{/* < 0 */

‎src/backend/utils/misc/guc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10528,7 +10528,7 @@ check_cluster_name(char **newval, void **extra, GucSource source)
1052810528
staticconstchar*
1052910529
show_unix_socket_permissions(void)
1053010530
{
10531-
staticcharbuf[8];
10531+
staticcharbuf[12];
1053210532

1053310533
snprintf(buf,sizeof(buf),"%04o",Unix_socket_permissions);
1053410534
returnbuf;
@@ -10537,7 +10537,7 @@ show_unix_socket_permissions(void)
1053710537
staticconstchar*
1053810538
show_log_file_mode(void)
1053910539
{
10540-
staticcharbuf[8];
10540+
staticcharbuf[12];
1054110541

1054210542
snprintf(buf,sizeof(buf),"%04o",Log_file_mode);
1054310543
returnbuf;

‎src/bin/initdb/initdb.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,12 +1009,12 @@ static char *
10091009
pretty_wal_size(intsegment_count)
10101010
{
10111011
intsz=wal_segment_size_mb*segment_count;
1012-
char*result=pg_malloc(11);
1012+
char*result=pg_malloc(14);
10131013

10141014
if ((sz %1024)==0)
1015-
snprintf(result,11,"%dGB",sz /1024);
1015+
snprintf(result,14,"%dGB",sz /1024);
10161016
else
1017-
snprintf(result,11,"%dMB",sz);
1017+
snprintf(result,14,"%dMB",sz);
10181018

10191019
returnresult;
10201020
}

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,7 @@ SetOutput(ArchiveHandle *AH, const char *filename, int compression)
15321532
#ifdefHAVE_LIBZ
15331533
if (compression!=0)
15341534
{
1535-
charfmode[10];
1535+
charfmode[14];
15361536

15371537
/* Don't use PG_BINARY_x since this is zlib */
15381538
sprintf(fmode,"wb%d",compression);

‎src/bin/pg_dump/pg_backup_tar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
335335
TAR_MEMBER*tm;
336336

337337
#ifdefHAVE_LIBZ
338-
charfmode[10];
338+
charfmode[14];
339339
#endif
340340

341341
if (mode=='r')

‎src/bin/pgbench/pgbench.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3591,7 +3591,7 @@ parseQuery(Command *cmd)
35913591
p=sql;
35923592
while ((p=strchr(p,':'))!=NULL)
35933593
{
3594-
charvar[12];
3594+
charvar[13];
35953595
char*name;
35963596
inteaten;
35973597

@@ -5432,7 +5432,7 @@ threadRun(void *arg)
54325432
sqlat,
54335433
lag,
54345434
stdev;
5435-
chartbuf[64];
5435+
chartbuf[315];
54365436

54375437
/*
54385438
* Add up the statistics of all threads.

‎src/include/postmaster/bgworker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ typedef enum
8282

8383
#defineBGW_DEFAULT_RESTART_INTERVAL60
8484
#defineBGW_NEVER_RESTART-1
85-
#defineBGW_MAXLEN64
85+
#defineBGW_MAXLEN96
8686
#defineBGW_EXTRALEN128
8787

8888
typedefstructBackgroundWorker

‎src/interfaces/libpq/fe-secure-openssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,7 @@ PQsslAttribute(PGconn *conn, const char *attribute_name)
14361436

14371437
if (strcmp(attribute_name,"key_bits")==0)
14381438
{
1439-
staticcharsslbits_str[10];
1439+
staticcharsslbits_str[12];
14401440
intsslbits;
14411441

14421442
SSL_get_cipher_bits(conn->ssl,&sslbits);

‎src/pl/tcl/pltcl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ compile_pltcl_function(Oid fn_oid, Oid tgreloid,
14561456
Datumprosrcdatum;
14571457
boolisnull;
14581458
char*proc_source;
1459-
charbuf[32];
1459+
charbuf[48];
14601460
Tcl_Interp*interp;
14611461
inti;
14621462
inttcl_rc;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp