From: Matthew Fernandez Date: Sat, 8 Aug 2020 01:02:05 +0000 (-0700) Subject: enable GCC and Clang to diagnose misuse of error() and errorf() X-Git-Tag: 2.46.0~20^2^2~126^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=57e05283950d901735d1435a92908540d5656d68;p=graphviz enable GCC and Clang to diagnose misuse of error() and errorf() This is the equivalent of 0a982672e53868cb394743a03b4e7b68951c282b for these lib/ast functions. --- diff --git a/lib/ast/error.h b/lib/ast/error.h index 8de5b62cd..ba7b841bd 100644 --- a/lib/ast/error.h +++ b/lib/ast/error.h @@ -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