Skip to content

Commit c02d5b7

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 except on Windows, where it is set to "gnu_printf", which eliminates hundreds of false error messages from modern versions of gcc arising from %m and %ll{d,u} formats.
1 parent 39850c7 commit c02d5b7

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
static char *
3434
psnprintf(size_t len, const char *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(const char *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
static void *pg_malloc(size_t size);
120120
static char *xstrdup(const char *s);
121121
static void do_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
extern void
154154
exit_horribly(Archive *AH, const char *modulename, const char *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 int archputs(const char *s, Archive *AH);
207207
extern int
208208
archprintf(Archive *AH, const char *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
#define appendStringLiteralAH(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
extern const char *progname;
330330

331-
extern void die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(printf, 3, 4)));
332-
extern void warn_or_die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(printf, 3, 4)));
333-
extern void write_msg(const char *modulename, const char *fmt,...) __attribute__((format(printf, 2, 3)));
331+
extern void die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
332+
extern void warn_or_die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
333+
extern void write_msg(const char *modulename, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
334334

335335
extern void WriteTOC(ArchiveHandle *AH);
336336
extern void ReadTOC(ArchiveHandle *AH);
@@ -378,8 +378,8 @@ extern int ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *
378378
extern void DropBlobIfExists(ArchiveHandle *AH, Oid oid);
379379

380380
int ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH);
381-
int ahprintf(ArchiveHandle *AH, const char *fmt,...) __attribute__((format(printf, 2, 3)));
381+
int ahprintf(ArchiveHandle *AH, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
382382

383-
void ahlog(ArchiveHandle *AH, int level, const char *fmt,...) __attribute__((format(printf, 3, 4)));
383+
void ahlog(ArchiveHandle *AH, int level, const char *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
extern void
3737
psql_error(const char *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
extern void NoticeProcessor(void *arg, const char *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
static void
1616
print_lo_result(const char *fmt,...)
17-
__attribute__((format(printf, 1, 2)));
17+
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
1818

1919
static void
2020
print_lo_result(const char *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
extern int
774774
snprintf(char *str, size_t count, const char *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
extern void
9696
appendStringInfo(StringInfo str, const char *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
#define MAX_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+
#ifdef WIN32
168+
#define PG_PRINTF_ATTRIBUTE gnu_printf
169+
#else
170+
#define PG_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 int pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
197197
extern int
198198
pg_snprintf(char *str, size_t count, const char *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
extern int
202202
pg_sprintf(char *str, const char *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
extern int pg_vfprintf(FILE *stream, const char *fmt, va_list args);
206206
extern int
207207
pg_fprintf(FILE *stream, const char *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
extern int
211211
pg_printf(const char *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(const char *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
extern int
130130
errmsg_internal(const char *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
extern int
136136
errmsg_plural(const char *fmt_singular, const char *fmt_plural,
137137
unsigned long n,...)
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
extern int
144144
errdetail(const char *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
extern int
150150
errdetail_log(const char *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
extern int
156156
errdetail_plural(const char *fmt_singular, const char *fmt_plural,
157157
unsigned long n,...)
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
extern int
164164
errhint(const char *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
extern int
170170
errcontext(const char *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
extern int errhidestmt(bool hide_stmt);
176176

@@ -197,7 +197,7 @@ extern void
197197
elog_finish(int elevel, const char *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(const char *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(const char *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
extern void
7777
mmerror(int, enum errortype, const char *,...)
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
extern void output_get_descr_header(char *);
8181
extern void output_get_descr(char *, char *);
8282
extern void output_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
extern void
506506
pqInternalNotice(const PGNoticeHooks *hooks, const char *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
extern int pqAddTuple(PGresult *res, PGresAttValue *tup);
510510
extern void pqSaveMessageField(PGresult *res, char code,
511511
const char *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 int enlargePQExpBuffer(PQExpBuffer str, size_t needed);
141141
extern void
142142
printfPQExpBuffer(PQExpBuffer str, const char *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
extern void
154154
appendPQExpBuffer(PQExpBuffer str, const char *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
static void
326326
PLy_exception_set(PyObject *, const char *,...)
327-
__attribute__((format(printf, 2, 3)));
327+
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
328328

329329
/* same, with pluralized message */
330330
static void
331331
PLy_exception_set_plural(PyObject *, const char *, const char *,
332332
unsigned long n,...)
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
static void PLy_spi_exception_set(PyObject *excclass, ErrorData *edata);
@@ -342,7 +342,7 @@ static char *PLy_procedure_name(PLyProcedure *);
342342
/* some utility functions */
343343
static void
344344
PLy_elog(int, const char *,...)
345-
__attribute__((format(printf, 2, 3)));
345+
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
346346
static void PLy_get_spi_error_data(PyObject *exc, char **detail, char **hint, char **query, int *position);
347347
static void PLy_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(const char *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
static void
131131
status(const char *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
static void
136136
psql_command(const char *database, const char *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
#ifdef WIN32
142142
typedef BOOL (WINAPI * __CreateRestrictedToken) (HANDLE, DWORD, DWORD, PSID_AND_ATTRIBUTES, DWORD, PLUID_AND_ATTRIBUTES, DWORD, PSID_AND_ATTRIBUTES, PHANDLE);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy