From e23d835f0f224d48f5c0b39a0f2bd18b342e703d Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 17 Jun 2005 21:01:28 +0000 Subject: [PATCH] Added more format string checks. --- lib/fastbuf.h | 4 ++-- lib/ff-printf.c | 4 ++-- lib/lib.h | 7 ++++--- lib/mempool.h | 2 +- lib/stkstring.h | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/fastbuf.h b/lib/fastbuf.h index ea71f120..905d046d 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -411,7 +411,7 @@ bdirect_write_commit(struct fastbuf *f, byte *pos) /* Formatted output */ -int bprintf(struct fastbuf *b, byte *msg, ...); -int vbprintf(struct fastbuf *b, byte *msg, va_list args); +int bprintf(struct fastbuf *b, char *msg, ...) FORMAT_CHECK(printf,2,3); +int vbprintf(struct fastbuf *b, char *msg, va_list args); #endif diff --git a/lib/ff-printf.c b/lib/ff-printf.c index cac06b55..fe9c9642 100644 --- a/lib/ff-printf.c +++ b/lib/ff-printf.c @@ -13,7 +13,7 @@ #include int -vbprintf(struct fastbuf *b, byte *msg, va_list args) +vbprintf(struct fastbuf *b, char *msg, va_list args) { byte *buf; int len, r; @@ -52,7 +52,7 @@ vbprintf(struct fastbuf *b, byte *msg, va_list args) } int -bprintf(struct fastbuf *b, byte *msg, ...) +bprintf(struct fastbuf *b, char *msg, ...) { va_list args; int res; diff --git a/lib/lib.h b/lib/lib.h index edb16e0f..00772320 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -53,6 +53,7 @@ #define PACKED __attribute__((packed)) #define CONST __attribute__((const)) #define PURE __attribute__((const)) +#define FORMAT_CHECK(x,y,z) __attribute__((format(x,y,z))) #define likely(x) __builtin_expect((x),1) #define unlikely(x) __builtin_expect((x),0) @@ -79,10 +80,10 @@ extern void (*log_die_hook)(void); struct tm; extern void (*log_switch_hook)(struct tm *tm); -void log_msg(unsigned int cat, const char *msg, ...) __attribute__((format(printf,2,3))); +void log_msg(unsigned int cat, const char *msg, ...) FORMAT_CHECK(printf,2,3); #define log log_msg void vlog_msg(unsigned int cat, const char *msg, va_list args); -void die(const char *, ...) NONRET __attribute__((format(printf,1,2))); +void die(const char *, ...) NONRET FORMAT_CHECK(printf,1,2); void log_init(byte *argv0); void log_file(byte *name); void log_fork(void); @@ -204,7 +205,7 @@ sh_off_t partmap_size(struct partmap *p); /* proctitle.c */ void setproctitle_init(int argc, char **argv); -void setproctitle(char *msg, ...) __attribute__((format(printf,1,2))); +void setproctitle(char *msg, ...) FORMAT_CHECK(printf,1,2); /* randomkey.c */ diff --git a/lib/mempool.h b/lib/mempool.h index 98d46e57..255e5389 100644 --- a/lib/mempool.h +++ b/lib/mempool.h @@ -72,7 +72,7 @@ mp_strcat(struct mempool *mp, char *x, char *y) /* mempool-fmt.c */ -char *mp_printf(struct mempool *p, char *fmt, ...); +char *mp_printf(struct mempool *p, char *fmt, ...) FORMAT_CHECK(printf,2,3); char *mp_vprintf(struct mempool *p, char *fmt, va_list args); #endif diff --git a/lib/stkstring.h b/lib/stkstring.h index 735d63e2..03f68904 100644 --- a/lib/stkstring.h +++ b/lib/stkstring.h @@ -18,6 +18,6 @@ uns stk_array_len(char **s, uns cnt); void stk_array_copy(char *x, char **s, uns cnt); -uns stk_printf_internal(char *x, ...) __attribute__((format(printf,1,2))); +uns stk_printf_internal(char *x, ...) FORMAT_CHECK(printf,1,2); extern char *stk_printf_buf; -- 2.39.2