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

Commitc02d5b7

Browse files
committed
Use a macro variable PG_PRINTF_ATTRIBUTE for the style used for checking printf type functions.
The style is set to "printf" for backwards compatibility everywhere excepton Windows, where it is set to "gnu_printf", which eliminates hundreds offalse error messages from modern versions of gcc arising from %m and %ll{d,u}formats.
1 parent39850c7 commitc02d5b7

File tree

16 files changed

+56
-41
lines changed

16 files changed

+56
-41
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static char *printTypmod(const char *typname, int32 typmod, Oid typmodout);
3333
staticchar*
3434
psnprintf(size_tlen,constchar*fmt,...)
3535
/* This lets gcc check the format string for consistency. */
36-
__attribute__((format(printf,2,3)));
36+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
3737

3838

3939
/*

‎src/bin/pg_ctl/pg_ctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static void
115115
write_stderr(constchar*fmt,...)
116116
/* This extension allows gcc to check the format string for consistency with
117117
the supplied arguments. */
118-
__attribute__((format(printf,1,2)));
118+
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,2)));
119119
staticvoid*pg_malloc(size_tsize);
120120
staticchar*xstrdup(constchar*s);
121121
staticvoiddo_advice(void);

‎src/bin/pg_dump/pg_backup.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ typedef struct _restoreOptions
152152

153153
externvoid
154154
exit_horribly(Archive*AH,constchar*modulename,constchar*fmt,...)
155-
__attribute__((format(printf,3,4)));
155+
__attribute__((format(PG_PRINTF_ATTRIBUTE,3,4)));
156156

157157

158158
/* Lets the archive know we have a DB connection to shutdown if it dies */
@@ -207,7 +207,7 @@ extern intarchputs(const char *s, Archive *AH);
207207
externint
208208
archprintf(Archive*AH,constchar*fmt,...)
209209
/* This extension allows gcc to check the format string */
210-
__attribute__((format(printf,2,3)));
210+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
211211

212212
#defineappendStringLiteralAH(buf,str,AH) \
213213
appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)

‎src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,9 @@ typedef struct _tocEntry
328328
/* Used everywhere */
329329
externconstchar*progname;
330330

331-
externvoiddie_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,...) __attribute__((format(printf,3,4)));
332-
externvoidwarn_or_die_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,...) __attribute__((format(printf,3,4)));
333-
externvoidwrite_msg(constchar*modulename,constchar*fmt,...) __attribute__((format(printf,2,3)));
331+
externvoiddie_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE,3,4)));
332+
externvoidwarn_or_die_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE,3,4)));
333+
externvoidwrite_msg(constchar*modulename,constchar*fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
334334

335335
externvoidWriteTOC(ArchiveHandle*AH);
336336
externvoidReadTOC(ArchiveHandle*AH);
@@ -378,8 +378,8 @@ extern intReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *
378378
externvoidDropBlobIfExists(ArchiveHandle*AH,Oidoid);
379379

380380
intahwrite(constvoid*ptr,size_tsize,size_tnmemb,ArchiveHandle*AH);
381-
intahprintf(ArchiveHandle*AH,constchar*fmt,...) __attribute__((format(printf,2,3)));
381+
intahprintf(ArchiveHandle*AH,constchar*fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
382382

383-
voidahlog(ArchiveHandle*AH,intlevel,constchar*fmt,...) __attribute__((format(printf,3,4)));
383+
voidahlog(ArchiveHandle*AH,intlevel,constchar*fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE,3,4)));
384384

385385
#endif

‎src/bin/psql/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extern bool setQFout(const char *fname);
3636
externvoid
3737
psql_error(constchar*fmt,...)
3838
/* This lets gcc check the format string for consistency. */
39-
__attribute__((format(printf,1,2)));
39+
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,2)));
4040

4141
externvoidNoticeProcessor(void*arg,constchar*message);
4242

‎src/bin/psql/large_obj.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
staticvoid
1616
print_lo_result(constchar*fmt,...)
17-
__attribute__((format(printf,1,2)));
17+
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,2)));
1818

1919
staticvoid
2020
print_lo_result(constchar*fmt,...)

‎src/include/c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ typedef NameData *Name;
773773
externint
774774
snprintf(char*str,size_tcount,constchar*fmt,...)
775775
/* This extension allows gcc to check the format string */
776-
__attribute__((format(printf,3,4)));
776+
__attribute__((format(PG_PRINTF_ATTRIBUTE,3,4)));
777777
#endif
778778

779779
#if !HAVE_DECL_VSNPRINTF

‎src/include/lib/stringinfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ extern void resetStringInfo(StringInfo str);
9595
externvoid
9696
appendStringInfo(StringInfostr,constchar*fmt,...)
9797
/* This extension allows gcc to check the format string */
98-
__attribute__((format(printf,2,3)));
98+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
9999

100100
/*------------------------
101101
* appendStringInfoVA

‎src/include/pg_config_manual.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,21 @@
154154
*/
155155
#defineMAX_RANDOM_VALUE (0x7FFFFFFF)
156156

157+
/*
158+
* Set the format style used by gcc to check printf type functions. We really
159+
* want the "gnu_printf" style set, which includes what glibc uses, such
160+
* as %m for error strings and %lld for 64 bit long longs. But not all gcc
161+
* compilers are known to support it, so we just use "printf" which all
162+
* gcc versions alive are known to support, except on Windows where
163+
* using "gnu_printf" style makes a dramatic difference. Maybe someday
164+
* we'll have a configure test for this, if we ever discover use of more
165+
* variants to be necessary.
166+
*/
167+
#ifdefWIN32
168+
#definePG_PRINTF_ATTRIBUTE gnu_printf
169+
#else
170+
#definePG_PRINTF_ATTRIBUTE printf
171+
#endif
157172

158173
/*
159174
*------------------------------------------------------------------------

‎src/include/port.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,20 @@ extern intpg_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
197197
externint
198198
pg_snprintf(char*str,size_tcount,constchar*fmt,...)
199199
/* This extension allows gcc to check the format string */
200-
__attribute__((format(printf,3,4)));
200+
__attribute__((format(PG_PRINTF_ATTRIBUTE,3,4)));
201201
externint
202202
pg_sprintf(char*str,constchar*fmt,...)
203203
/* This extension allows gcc to check the format string */
204-
__attribute__((format(printf,2,3)));
204+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
205205
externintpg_vfprintf(FILE*stream,constchar*fmt,va_listargs);
206206
externint
207207
pg_fprintf(FILE*stream,constchar*fmt,...)
208208
/* This extension allows gcc to check the format string */
209-
__attribute__((format(printf,2,3)));
209+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
210210
externint
211211
pg_printf(constchar*fmt,...)
212212
/* This extension allows gcc to check the format string */
213-
__attribute__((format(printf,1,2)));
213+
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,2)));
214214

215215
/*
216216
*The GCC-specific code below prevents the __attribute__(... 'printf')

‎src/include/utils/elog.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,53 +124,53 @@ extern int
124124
errmsg(constchar*fmt,...)
125125
/* This extension allows gcc to check the format string for consistency with
126126
the supplied arguments. */
127-
__attribute__((format(printf,1,2)));
127+
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,2)));
128128

129129
externint
130130
errmsg_internal(constchar*fmt,...)
131131
/* This extension allows gcc to check the format string for consistency with
132132
the supplied arguments. */
133-
__attribute__((format(printf,1,2)));
133+
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,2)));
134134

135135
externint
136136
errmsg_plural(constchar*fmt_singular,constchar*fmt_plural,
137137
unsigned longn,...)
138138
/* This extension allows gcc to check the format string for consistency with
139139
the supplied arguments. */
140-
__attribute__((format(printf,1,4)))
141-
__attribute__((format(printf,2,4)));
140+
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,4)))
141+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,4)));
142142

143143
externint
144144
errdetail(constchar*fmt,...)
145145
/* This extension allows gcc to check the format string for consistency with
146146
the supplied arguments. */
147-
__attribute__((format(printf,1,2)));
147+
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,2)));
148148

149149
externint
150150
errdetail_log(constchar*fmt,...)
151151
/* This extension allows gcc to check the format string for consistency with
152152
the supplied arguments. */
153-
__attribute__((format(printf,1,2)));
153+
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,2)));
154154

155155
externint
156156
errdetail_plural(constchar*fmt_singular,constchar*fmt_plural,
157157
unsigned longn,...)
158158
/* This extension allows gcc to check the format string for consistency with
159159
the supplied arguments. */
160-
__attribute__((format(printf,1,4)))
161-
__attribute__((format(printf,2,4)));
160+
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,4)))
161+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,4)));
162162

163163
externint
164164
errhint(constchar*fmt,...)
165165
/* This extension allows gcc to check the format string for consistency with
166166
the supplied arguments. */
167-
__attribute__((format(printf,1,2)));
167+
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,2)));
168168

169169
externint
170170
errcontext(constchar*fmt,...)
171171
/* This extension allows gcc to check the format string for consistency with
172172
the supplied arguments. */
173-
__attribute__((format(printf,1,2)));
173+
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,2)));
174174

175175
externinterrhidestmt(boolhide_stmt);
176176

@@ -197,7 +197,7 @@ extern void
197197
elog_finish(intelevel,constchar*fmt,...)
198198
/* This extension allows gcc to check the format string for consistency with
199199
the supplied arguments. */
200-
__attribute__((format(printf,2,3)));
200+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
201201

202202

203203
/* Support for constructing error strings separately from ereport() calls */
@@ -207,7 +207,7 @@ extern char *
207207
format_elog_string(constchar*fmt,...)
208208
/* This extension allows gcc to check the format string for consistency with
209209
the supplied arguments. */
210-
__attribute__((format(printf,1,2)));
210+
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,2)));
211211

212212

213213
/* Support for attaching context information to error reports */
@@ -366,6 +366,6 @@ extern void
366366
write_stderr(constchar*fmt,...)
367367
/* This extension allows gcc to check the format string for consistency with
368368
the supplied arguments. */
369-
__attribute__((format(printf,1,2)));
369+
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,2)));
370370

371371
#endif/* ELOG_H */

‎src/interfaces/ecpg/preproc/extern.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ extern char *mm_strdup(const char *);
7676
externvoid
7777
mmerror(int,enumerrortype,constchar*,...)
7878
/* This extension allows gcc to check the format string */
79-
__attribute__((format(printf,3,4)));
79+
__attribute__((format(PG_PRINTF_ATTRIBUTE,3,4)));
8080
externvoidoutput_get_descr_header(char*);
8181
externvoidoutput_get_descr(char*,char*);
8282
externvoidoutput_set_descr_header(char*);

‎src/interfaces/libpq/libpq-int.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ extern PGresult *pqPrepareAsyncResult(PGconn *conn);
505505
externvoid
506506
pqInternalNotice(constPGNoticeHooks*hooks,constchar*fmt,...)
507507
/* This lets gcc check the format string for consistency. */
508-
__attribute__((format(printf,2,3)));
508+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
509509
externintpqAddTuple(PGresult*res,PGresAttValue*tup);
510510
externvoidpqSaveMessageField(PGresult*res,charcode,
511511
constchar*value);

‎src/interfaces/libpq/pqexpbuffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ extern intenlargePQExpBuffer(PQExpBuffer str, size_t needed);
141141
externvoid
142142
printfPQExpBuffer(PQExpBufferstr,constchar*fmt,...)
143143
/* This extension allows gcc to check the format string */
144-
__attribute__((format(printf,2,3)));
144+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
145145

146146
/*------------------------
147147
* appendPQExpBuffer
@@ -153,7 +153,7 @@ __attribute__((format(printf, 2, 3)));
153153
externvoid
154154
appendPQExpBuffer(PQExpBufferstr,constchar*fmt,...)
155155
/* This extension allows gcc to check the format string */
156-
__attribute__((format(printf,2,3)));
156+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
157157

158158
/*------------------------
159159
* appendPQExpBufferStr

‎src/pl/plpython/plpython.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,14 @@ static void PLy_init_plpy(void);
324324
/* call PyErr_SetString with a vprint interface and translation support */
325325
staticvoid
326326
PLy_exception_set(PyObject*,constchar*,...)
327-
__attribute__((format(printf,2,3)));
327+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
328328

329329
/* same, with pluralized message */
330330
staticvoid
331331
PLy_exception_set_plural(PyObject*,constchar*,constchar*,
332332
unsigned longn,...)
333-
__attribute__((format(printf,2,5)))
334-
__attribute__((format(printf,3,5)));
333+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,5)))
334+
__attribute__((format(PG_PRINTF_ATTRIBUTE,3,5)));
335335

336336
/* like PLy_exception_set, but conserve more fields from ErrorData */
337337
staticvoidPLy_spi_exception_set(PyObject*excclass,ErrorData*edata);
@@ -342,7 +342,7 @@ static char *PLy_procedure_name(PLyProcedure *);
342342
/* some utility functions */
343343
staticvoid
344344
PLy_elog(int,constchar*,...)
345-
__attribute__((format(printf,2,3)));
345+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
346346
staticvoidPLy_get_spi_error_data(PyObject*exc,char**detail,char**hint,char**query,int*position);
347347
staticvoidPLy_traceback(char**,char**,int*);
348348

‎src/test/regress/pg_regress.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,17 @@ static void
126126
header(constchar*fmt,...)
127127
/* This extension allows gcc to check the format string for consistency with
128128
the supplied arguments. */
129-
__attribute__((format(printf,1,2)));
129+
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,2)));
130130
staticvoid
131131
status(constchar*fmt,...)
132132
/* This extension allows gcc to check the format string for consistency with
133133
the supplied arguments. */
134-
__attribute__((format(printf,1,2)));
134+
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,2)));
135135
staticvoid
136136
psql_command(constchar*database,constchar*query,...)
137137
/* This extension allows gcc to check the format string for consistency with
138138
the supplied arguments. */
139-
__attribute__((format(printf,2,3)));
139+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
140140

141141
#ifdefWIN32
142142
typedefBOOL (WINAPI*__CreateRestrictedToken) (HANDLE,DWORD,DWORD,PSID_AND_ATTRIBUTES,DWORD,PLUID_AND_ATTRIBUTES,DWORD,PSID_AND_ATTRIBUTES,PHANDLE);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp