Consistently use gcc's __attribute__((format)) to check sprintf-style
format strings wherever possible. Remarkably, this exercise didn't turn up any inconsistencies, but it seems a good idea for the future.
This commit is contained in:
parent
2e5fda7b7e
commit
fcd2e372a7
@ -37,7 +37,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.244 2001/09/30 20:08:18 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.245 2001/10/03 21:58:28 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
*
|
||||
@ -251,13 +251,9 @@ static void SignalChildren(int signal);
|
||||
static int CountChildren(void);
|
||||
static bool CreateOptsFile(int argc, char *argv[]);
|
||||
static pid_t SSDataBase(int xlop);
|
||||
#ifdef __GNUC__
|
||||
/* This checks the format string for consistency. */
|
||||
static void postmaster_error(const char *fmt, ...)
|
||||
__attribute__((format(printf, 1, 2)));
|
||||
#else
|
||||
static void postmaster_error(const char *fmt, ...);
|
||||
#endif
|
||||
/* This lets gcc check the format string for consistency. */
|
||||
__attribute__((format(printf, 1, 2)));
|
||||
|
||||
#define StartupDataBase() SSDataBase(BS_XLOG_STARTUP)
|
||||
#define CheckPointDataBase() SSDataBase(BS_XLOG_CHECKPOINT)
|
||||
|
@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.14 2001/08/22 20:23:23 petere Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.15 2001/10/03 21:58:28 tgl Exp $
|
||||
*
|
||||
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
|
||||
*
|
||||
@ -130,7 +130,8 @@ typedef struct _restoreOptions
|
||||
* Main archiver interface.
|
||||
*/
|
||||
|
||||
extern void exit_horribly(Archive *AH, const char *modulename, const char *fmt, ...) __attribute__((format(printf,3,4)));
|
||||
extern void exit_horribly(Archive *AH, const char *modulename, const char *fmt, ...)
|
||||
__attribute__((format(printf,3,4)));
|
||||
|
||||
extern char *
|
||||
simple_prompt(const char *prompt, int maxlen, bool echo);
|
||||
@ -188,6 +189,8 @@ extern void SortTocFromFile(Archive *AH, RestoreOptions *ropt);
|
||||
/* Convenience functions used only when writing DATA */
|
||||
extern int archputs(const char *s, Archive *AH);
|
||||
extern int archputc(const char c, Archive *AH);
|
||||
extern int archprintf(Archive *AH, const char *fmt,...);
|
||||
extern int archprintf(Archive *AH, const char *fmt, ...)
|
||||
/* This extension allows gcc to check the format string */
|
||||
__attribute__((format(printf, 2, 3)));
|
||||
|
||||
#endif
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright 2000 by PostgreSQL Global Development Group
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.13 2001/02/10 02:31:28 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.14 2001/10/03 21:58:28 tgl Exp $
|
||||
*/
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
@ -13,33 +13,28 @@
|
||||
#include "pqsignal.h"
|
||||
#include "libpq-fe.h"
|
||||
|
||||
char *xstrdup(const char *string);
|
||||
extern char *xstrdup(const char *string);
|
||||
|
||||
bool setQFout(const char *fname);
|
||||
extern bool setQFout(const char *fname);
|
||||
|
||||
#ifndef __GNUC__
|
||||
void psql_error(const char *fmt,...);
|
||||
extern void psql_error(const char *fmt, ...)
|
||||
/* This lets gcc check the format string for consistency. */
|
||||
__attribute__((format(printf, 1, 2)));
|
||||
|
||||
#else
|
||||
/* This checks the format string for consistency. */
|
||||
void psql_error(const char *fmt,...) __attribute__((format(printf, 1, 2)));
|
||||
extern void NoticeProcessor(void *arg, const char *message);
|
||||
|
||||
#endif
|
||||
|
||||
void NoticeProcessor(void *arg, const char *message);
|
||||
|
||||
char *simple_prompt(const char *prompt, int maxlen, bool echo);
|
||||
extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
|
||||
|
||||
extern volatile bool cancel_pressed;
|
||||
extern PGconn *cancelConn;
|
||||
|
||||
#ifndef WIN32
|
||||
void handle_sigint(SIGNAL_ARGS);
|
||||
extern void handle_sigint(SIGNAL_ARGS);
|
||||
|
||||
#endif /* not WIN32 */
|
||||
|
||||
PGresult *PSQLexec(const char *query);
|
||||
extern PGresult *PSQLexec(const char *query);
|
||||
|
||||
bool SendQuery(const char *query);
|
||||
extern bool SendQuery(const char *query);
|
||||
|
||||
#endif /* COMMON_H */
|
||||
|
@ -12,7 +12,7 @@
|
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: c.h,v 1.101 2001/08/27 23:02:25 tgl Exp $
|
||||
* $Id: c.h,v 1.102 2001/10/03 21:58:28 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -634,13 +634,13 @@ typedef NameData *Name;
|
||||
*/
|
||||
|
||||
#ifndef HAVE_SNPRINTF_DECL
|
||||
extern int snprintf(char *str, size_t count, const char *fmt,...);
|
||||
|
||||
extern int snprintf(char *str, size_t count, const char *fmt, ...)
|
||||
/* This extension allows gcc to check the format string */
|
||||
__attribute__((format(printf, 3, 4)));
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_VSNPRINTF_DECL
|
||||
extern int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_MEMMOVE) && !defined(memmove)
|
||||
|
@ -10,7 +10,7 @@
|
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: stringinfo.h,v 1.19 2001/01/24 19:43:24 momjian Exp $
|
||||
* $Id: stringinfo.h,v 1.20 2001/10/03 21:58:28 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -81,7 +81,9 @@ extern void initStringInfo(StringInfo str);
|
||||
* to str if necessary. This is sort of like a combination of sprintf and
|
||||
* strcat.
|
||||
*/
|
||||
extern void appendStringInfo(StringInfo str, const char *fmt,...);
|
||||
extern void appendStringInfo(StringInfo str, const char *fmt, ...)
|
||||
/* This extension allows gcc to check the format string */
|
||||
__attribute__((format(printf, 2, 3)));
|
||||
|
||||
/*------------------------
|
||||
* appendStringInfoChar
|
||||
|
@ -10,7 +10,7 @@
|
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1995, Regents of the University of California
|
||||
*
|
||||
* $Id: postgres.h,v 1.52 2001/08/24 22:46:28 petere Exp $
|
||||
* $Id: postgres.h,v 1.53 2001/10/03 21:58:28 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -562,7 +562,10 @@ extern DLLIMPORT bool assert_enabled;
|
||||
extern int ExceptionalCondition(char *conditionName,
|
||||
Exception *exceptionP, char *details,
|
||||
char *fileName, int lineNumber);
|
||||
extern char *vararg_format(const char *fmt,...);
|
||||
|
||||
extern char *vararg_format(const char *fmt, ...)
|
||||
/* This lets gcc check the format string for consistency. */
|
||||
__attribute__((format(printf, 1, 2)));
|
||||
|
||||
#ifndef USE_ASSERT_CHECKING
|
||||
#define LogAssert(condition, printArgs)
|
||||
|
@ -12,7 +12,7 @@
|
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: libpq-int.h,v 1.39 2001/08/17 02:59:20 momjian Exp $
|
||||
* $Id: libpq-int.h,v 1.40 2001/10/03 21:58:28 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -346,10 +346,7 @@ extern int pqWriteReady(PGconn *conn);
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
extern char * libpq_gettext(const char *msgid)
|
||||
#ifdef __GNUC__
|
||||
__attribute__((format_arg(1)))
|
||||
#endif
|
||||
;
|
||||
__attribute__((format_arg(1)));
|
||||
#else
|
||||
#define libpq_gettext(x) (x)
|
||||
#endif
|
||||
|
@ -18,7 +18,7 @@
|
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: pqexpbuffer.h,v 1.6 2001/01/24 19:43:31 momjian Exp $
|
||||
* $Id: pqexpbuffer.h,v 1.7 2001/10/03 21:58:28 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -122,7 +122,9 @@ extern int enlargePQExpBuffer(PQExpBuffer str, size_t needed);
|
||||
* This is a convenience routine that does the same thing as
|
||||
* resetPQExpBuffer() followed by appendPQExpBuffer().
|
||||
*/
|
||||
extern void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...);
|
||||
extern void printfPQExpBuffer(PQExpBuffer str, const char *fmt, ...)
|
||||
/* This extension allows gcc to check the format string */
|
||||
__attribute__((format(printf, 2, 3)));
|
||||
|
||||
/*------------------------
|
||||
* appendPQExpBuffer
|
||||
@ -131,7 +133,9 @@ extern void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...);
|
||||
* to str if necessary. This is sort of like a combination of sprintf and
|
||||
* strcat.
|
||||
*/
|
||||
extern void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...);
|
||||
extern void appendPQExpBuffer(PQExpBuffer str, const char *fmt, ...)
|
||||
/* This extension allows gcc to check the format string */
|
||||
__attribute__((format(printf, 2, 3)));
|
||||
|
||||
/*------------------------
|
||||
* appendPQExpBufferStr
|
||||
|
Loading…
x
Reference in New Issue
Block a user