]> granicus.if.org Git - graphviz/commitdiff
enable GCC and Clang to diagnose misuse of error() and errorf()
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 8 Aug 2020 01:02:05 +0000 (18:02 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 13 Aug 2020 14:38:13 +0000 (07:38 -0700)
This is the equivalent of 0a982672e53868cb394743a03b4e7b68951c282b for these
lib/ast functions.

lib/ast/error.h

index 8de5b62cd6bf5b1657bea7aad8d09f607f4a0bbc..ba7b841bde7c33487b74827bf14732f7e66899af 100644 (file)
@@ -53,6 +53,13 @@ extern "C" {
 #define error          _err_msg
 #define errorv         _err_msgv
 
+/* support for extra API misuse warnings if available */
+#ifdef __GNUC__
+  #define PRINTF_LIKE(index, first) __attribute__((format(printf, index, first)))
+#else
+  #define PRINTF_LIKE(index, first) /* nothing */
+#endif
+
     extern Error_info_t error_info;
 
     extern void setTraceLevel (int);
@@ -62,10 +69,12 @@ extern "C" {
     extern void setErrorErrors (int);
     extern int  getErrorErrors (void);
 
-    extern void error(int, const char *, ...);
-    extern void errorf(void *, void *, int, const char *, ...);
+    extern void error(int, const char *, ...) PRINTF_LIKE(2, 3);
+    extern void errorf(void *, void *, int, const char *, ...) PRINTF_LIKE(4, 5);
     extern void errorv(const char *, int, const char *, va_list);
 
+#undef PRINTF_LIKE
+
 #endif
 
 #ifdef __cplusplus