From: Todd C. Miller Date: Fri, 11 Feb 2005 23:06:35 +0000 (+0000) Subject: Add __printflike and use it with gcc to warn about printf-like format mismatches X-Git-Tag: SUDO_1_7_0~708 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b3b65fb7fc2657db1d04922e464df258cde11b34;p=sudo Add __printflike and use it with gcc to warn about printf-like format mismatches --- diff --git a/compat.h b/compat.h index d514fcd2f..224db4596 100644 --- a/compat.h +++ b/compat.h @@ -50,6 +50,15 @@ # endif #endif +/* For catching format string mismatches */ +#ifndef __printflike +# if defined(__GNUC__) && (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ >= 7) +# define __printflike(f, v) __attribute__((__format__ (__printf__, f, v))) +# else +# define __printflike(f, v) +# endif +#endif + /* * Some systems lack full limit definitions. */ diff --git a/logging.h b/logging.h index add20a55d..845023f59 100644 --- a/logging.h +++ b/logging.h @@ -47,7 +47,8 @@ #endif void log_auth __P((int, int)); -void log_error __P((int flags, const char *fmt, ...)); +void log_error __P((int flags, const char *fmt, ...)) + __printflike(2, 3); RETSIGTYPE reapchild __P((int)); #endif /* _LOGGING_H */ diff --git a/sudo.h b/sudo.h index 9e909f181..412c17622 100644 --- a/sudo.h +++ b/sudo.h @@ -183,16 +183,20 @@ int utimes __P((const char *, const struct timeval *)); int futimes __P((int, const struct timeval *)); #endif #ifndef HAVE_SNPRINTF -int snprintf __P((char *, size_t, const char *, ...)); +int snprintf __P((char *, size_t, const char *, ...)) + __printflike(3, 4); #endif #ifndef HAVE_VSNPRINTF -int vsnprintf __P((char *, size_t, const char *, va_list)); +int vsnprintf __P((char *, size_t, const char *, va_list)) + __printflike(3, 0); #endif #ifndef HAVE_ASPRINTF -int asprintf __P((char **, const char *, ...)); +int asprintf __P((char **, const char *, ...)) + __printflike(2, 3); #endif #ifndef HAVE_VASPRINTF -int vasprintf __P((char **, const char *, va_list)); +int vasprintf __P((char **, const char *, va_list)) + __printflike(2, 0); #endif #ifndef HAVE_STRCASECMP int strcasecmp __P((const char *, const char *)); @@ -229,8 +233,10 @@ VOID *emalloc2 __P((size_t, size_t)); VOID *erealloc __P((VOID *, size_t)); VOID *erealloc3 __P((VOID *, size_t, size_t)); char *estrdup __P((const char *)); -int easprintf __P((char **, const char *, ...)); -int evasprintf __P((char **, const char *, va_list)); +int easprintf __P((char **, const char *, ...)) + __printflike(2, 3); +int evasprintf __P((char **, const char *, va_list)) + __printflike(2, 0); void dump_defaults __P((void)); void dump_auth_methods __P((void)); void init_envtables __P((void));