]> granicus.if.org Git - sudo/commitdiff
Add __printflike and use it with gcc to warn about printf-like format mismatches
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 11 Feb 2005 23:06:35 +0000 (23:06 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 11 Feb 2005 23:06:35 +0000 (23:06 +0000)
compat.h
logging.h
sudo.h

index d514fcd2f9e0baf34747d3b0a2835455c6336dad..224db4596138b80816a3adb1ca4ddc8981844e53 100644 (file)
--- a/compat.h
+++ b/compat.h
 # 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.
  */
index add20a55d943b597050342160b538d814c87f16f..845023f59e48f3a97ffc38d29cea18e502747d3a 100644 (file)
--- 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 9e909f181b310eaea2f0ca64137657e53093b27d..412c17622e3fb96d57a4f39c41c28a73bd02af00 100644 (file)
--- 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));