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')

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