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

Commitfcd2e37

Browse files
committed
Consistently use gcc's __attribute__((format)) to check sprintf-style
format strings wherever possible. Remarkably, this exercise didn'tturn up any inconsistencies, but it seems a good idea for the future.
1 parent2e5fda7 commitfcd2e37

File tree

8 files changed

+42
-42
lines changed

8 files changed

+42
-42
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.244 2001/09/30 20:08:18 tgl Exp $
40+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.245 2001/10/03 21:58:28 tgl Exp $
4141
*
4242
* NOTES
4343
*
@@ -251,13 +251,9 @@ static void SignalChildren(int signal);
251251
staticintCountChildren(void);
252252
staticboolCreateOptsFile(intargc,char*argv[]);
253253
staticpid_tSSDataBase(intxlop);
254-
#ifdef__GNUC__
255-
/* This checks the format string for consistency. */
256254
staticvoidpostmaster_error(constchar*fmt, ...)
257-
__attribute__((format(printf,1,2)));
258-
#else
259-
staticvoidpostmaster_error(constchar*fmt, ...);
260-
#endif
255+
/* This lets gcc check the format string for consistency. */
256+
__attribute__((format(printf,1,2)));
261257

262258
#defineStartupDataBase()SSDataBase(BS_XLOG_STARTUP)
263259
#defineCheckPointDataBase()SSDataBase(BS_XLOG_CHECKPOINT)

‎src/bin/pg_dump/pg_backup.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.14 2001/08/22 20:23:23 petere Exp $
18+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.15 2001/10/03 21:58:28 tgl Exp $
1919
*
2020
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2121
*
@@ -130,7 +130,8 @@ typedef struct _restoreOptions
130130
* Main archiver interface.
131131
*/
132132

133-
externvoidexit_horribly(Archive*AH,constchar*modulename,constchar*fmt, ...) __attribute__((format(printf,3,4)));
133+
externvoidexit_horribly(Archive*AH,constchar*modulename,constchar*fmt, ...)
134+
__attribute__((format(printf,3,4)));
134135

135136
externchar*
136137
simple_prompt(constchar*prompt,intmaxlen,boolecho);
@@ -188,6 +189,8 @@ extern void SortTocFromFile(Archive *AH, RestoreOptions *ropt);
188189
/* Convenience functions used only when writing DATA */
189190
externintarchputs(constchar*s,Archive*AH);
190191
externintarchputc(constcharc,Archive*AH);
191-
externintarchprintf(Archive*AH,constchar*fmt,...);
192+
externintarchprintf(Archive*AH,constchar*fmt, ...)
193+
/* This extension allows gcc to check the format string */
194+
__attribute__((format(printf,2,3)));
192195

193196
#endif

‎src/bin/psql/common.h

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.13 2001/02/10 02:31:28 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.14 2001/10/03 21:58:28 tgl Exp $
77
*/
88
#ifndefCOMMON_H
99
#defineCOMMON_H
@@ -13,33 +13,28 @@
1313
#include"pqsignal.h"
1414
#include"libpq-fe.h"
1515

16-
char*xstrdup(constchar*string);
16+
externchar*xstrdup(constchar*string);
1717

18-
boolsetQFout(constchar*fname);
18+
externboolsetQFout(constchar*fname);
1919

20-
#ifndef__GNUC__
21-
voidpsql_error(constchar*fmt,...);
20+
externvoidpsql_error(constchar*fmt, ...)
21+
/* This lets gcc check the format string for consistency. */
22+
__attribute__((format(printf,1,2)));
2223

23-
#else
24-
/* This checks the format string for consistency. */
25-
voidpsql_error(constchar*fmt,...) __attribute__((format(printf,1,2)));
24+
externvoidNoticeProcessor(void*arg,constchar*message);
2625

27-
#endif
28-
29-
voidNoticeProcessor(void*arg,constchar*message);
30-
31-
char*simple_prompt(constchar*prompt,intmaxlen,boolecho);
26+
externchar*simple_prompt(constchar*prompt,intmaxlen,boolecho);
3227

3328
externvolatileboolcancel_pressed;
3429
externPGconn*cancelConn;
3530

3631
#ifndefWIN32
37-
voidhandle_sigint(SIGNAL_ARGS);
32+
externvoidhandle_sigint(SIGNAL_ARGS);
3833

3934
#endif/* not WIN32 */
4035

41-
PGresult*PSQLexec(constchar*query);
36+
externPGresult*PSQLexec(constchar*query);
4237

43-
boolSendQuery(constchar*query);
38+
externboolSendQuery(constchar*query);
4439

4540
#endif/* COMMON_H */

‎src/include/c.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $Id: c.h,v 1.101 2001/08/27 23:02:25 tgl Exp $
15+
* $Id: c.h,v 1.102 2001/10/03 21:58:28 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -634,13 +634,13 @@ typedef NameData *Name;
634634
*/
635635

636636
#ifndefHAVE_SNPRINTF_DECL
637-
externintsnprintf(char*str,size_tcount,constchar*fmt,...);
638-
637+
externintsnprintf(char*str,size_tcount,constchar*fmt, ...)
638+
/* This extension allows gcc to check the format string */
639+
__attribute__((format(printf,3,4)));
639640
#endif
640641

641642
#ifndefHAVE_VSNPRINTF_DECL
642643
externintvsnprintf(char*str,size_tcount,constchar*fmt,va_listargs);
643-
644644
#endif
645645

646646
#if !defined(HAVE_MEMMOVE)&& !defined(memmove)

‎src/include/lib/stringinfo.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
13-
* $Id: stringinfo.h,v 1.19 2001/01/24 19:43:24 momjian Exp $
13+
* $Id: stringinfo.h,v 1.20 2001/10/03 21:58:28 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -81,7 +81,9 @@ extern void initStringInfo(StringInfo str);
8181
* to str if necessary. This is sort of like a combination of sprintf and
8282
* strcat.
8383
*/
84-
externvoidappendStringInfo(StringInfostr,constchar*fmt,...);
84+
externvoidappendStringInfo(StringInfostr,constchar*fmt, ...)
85+
/* This extension allows gcc to check the format string */
86+
__attribute__((format(printf,2,3)));
8587

8688
/*------------------------
8789
* appendStringInfoChar

‎src/include/postgres.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
1111
* Portions Copyright (c) 1995, Regents of the University of California
1212
*
13-
* $Id: postgres.h,v 1.52 2001/08/24 22:46:28petere Exp $
13+
* $Id: postgres.h,v 1.53 2001/10/03 21:58:28tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -562,7 +562,10 @@ extern DLLIMPORT bool assert_enabled;
562562
externintExceptionalCondition(char*conditionName,
563563
Exception*exceptionP,char*details,
564564
char*fileName,intlineNumber);
565-
externchar*vararg_format(constchar*fmt,...);
565+
566+
externchar*vararg_format(constchar*fmt, ...)
567+
/* This lets gcc check the format string for consistency. */
568+
__attribute__((format(printf,1,2)));
566569

567570
#ifndefUSE_ASSERT_CHECKING
568571
#defineLogAssert(condition,printArgs)

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $Id: libpq-int.h,v 1.39 2001/08/17 02:59:20 momjian Exp $
15+
* $Id: libpq-int.h,v 1.40 2001/10/03 21:58:28 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -346,10 +346,7 @@ extern intpqWriteReady(PGconn *conn);
346346

347347
#ifdefENABLE_NLS
348348
externchar*libpq_gettext(constchar*msgid)
349-
#ifdef__GNUC__
350-
__attribute__((format_arg(1)))
351-
#endif
352-
;
349+
__attribute__((format_arg(1)));
353350
#else
354351
#definelibpq_gettext(x) (x)
355352
#endif

‎src/interfaces/libpq/pqexpbuffer.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
1919
* Portions Copyright (c) 1994, Regents of the University of California
2020
*
21-
* $Id: pqexpbuffer.h,v 1.6 2001/01/24 19:43:31 momjian Exp $
21+
* $Id: pqexpbuffer.h,v 1.7 2001/10/03 21:58:28 tgl Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -122,7 +122,9 @@ extern intenlargePQExpBuffer(PQExpBuffer str, size_t needed);
122122
* This is a convenience routine that does the same thing as
123123
* resetPQExpBuffer() followed by appendPQExpBuffer().
124124
*/
125-
externvoidprintfPQExpBuffer(PQExpBufferstr,constchar*fmt,...);
125+
externvoidprintfPQExpBuffer(PQExpBufferstr,constchar*fmt, ...)
126+
/* This extension allows gcc to check the format string */
127+
__attribute__((format(printf,2,3)));
126128

127129
/*------------------------
128130
* appendPQExpBuffer
@@ -131,7 +133,9 @@ extern void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...);
131133
* to str if necessary. This is sort of like a combination of sprintf and
132134
* strcat.
133135
*/
134-
externvoidappendPQExpBuffer(PQExpBufferstr,constchar*fmt,...);
136+
externvoidappendPQExpBuffer(PQExpBufferstr,constchar*fmt, ...)
137+
/* This extension allows gcc to check the format string */
138+
__attribute__((format(printf,2,3)));
135139

136140
/*------------------------
137141
* appendPQExpBufferStr

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp