From 2711701beb3c8d97b2baced76de03a1a69510823 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Tue, 19 Nov 2019 19:24:41 +0000 Subject: [PATCH] rdisc / ninfod: fix format string warning warning: format string is not a string literal [-Wformat-nonliteral] The above was reported for rdisc.c lines 210 and 212, and ninfod/ninfod.c lines 162 and 165. Reviewed-by: Petr Vorel Signed-off-by: Sami Kerola --- iputils_common.h | 6 ++++++ ninfod/ninfod.c | 3 ++- ninfod/ninfod.h | 2 +- rdisc.c | 3 ++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/iputils_common.h b/iputils_common.h index 82a77f0d..26e8f7c4 100644 --- a/iputils_common.h +++ b/iputils_common.h @@ -10,6 +10,12 @@ !!__builtin_types_compatible_p(__typeof__(arr), \ __typeof__(&arr[0]))])) * 0) +#ifdef __GNUC__ +# define iputils_attribute_format(t, n, m) __attribute__((__format__ (t, n, m))) +#else +# define iputils_attribute_format(t, n, m) +#endif + #if defined(USE_IDN) || defined(ENABLE_NLS) # include #endif diff --git a/ninfod/ninfod.c b/ninfod/ninfod.c index badbf809..26112d0d 100644 --- a/ninfod/ninfod.c +++ b/ninfod/ninfod.c @@ -151,7 +151,8 @@ __inline__ static const char * log_level(int priority) { } } -void DEBUG(int pri, char *fmt, ...) +iputils_attribute_format(__printf__, 2, 3) +void DEBUG(int const pri, char const *const fmt, ...) { int saved_errno = errno; va_list ap; diff --git a/ninfod/ninfod.h b/ninfod/ninfod.h index 94c895ec..75dc5c1c 100644 --- a/ninfod/ninfod.h +++ b/ninfod/ninfod.h @@ -102,7 +102,7 @@ int ni_recv(struct packetcontext *p); int ni_send(struct packetcontext *p); /* ninfod_core.c */ -extern void DEBUG(int pri, char *fmt, ...); +extern void DEBUG(int const pri, char const *const fmt, ...); void init_core(int forced); int pr_nodeinfo(struct packetcontext *p); diff --git a/rdisc.c b/rdisc.c index fb937077..1cf6327b 100644 --- a/rdisc.c +++ b/rdisc.c @@ -201,7 +201,8 @@ static unsigned short in_cksum(unsigned short *addr, int len); static int logging = 0; -static void logmsg(int prio, char *fmt, ...) +iputils_attribute_format(__printf__, 2, 3) +static void logmsg(int const prio, char const *const fmt, ...) { va_list ap;