From 36dbacfaa5b0f726fc5b1e987970736184cd30a3 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 9 Oct 2021 12:05:37 -0700 Subject: [PATCH] exerror/exwarn: allow GNU-compatible compilers to detect misuse This lets compilers like GCC and Clang notice when these functions are called with a format string that is inconsistent with the remaining arguments and issue a warning. This detects problems like those fixed in the prior commit. --- lib/expr/expr.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/expr/expr.h b/lib/expr/expr.h index 4c3630687..9c4e91233 100644 --- a/lib/expr/expr.h +++ b/lib/expr/expr.h @@ -271,7 +271,13 @@ extern void exclose(Expr_t*, int); extern int excomp(Expr_t*, const char*, int, const char*, Sfio_t*); extern char* excontext(Expr_t*, char*, int); extern int exdump(Expr_t*, Exnode_t*, Sfio_t*); +#ifdef __GNUC__ +__attribute__((format(printf, 1, 2))) +#endif extern void exerror(const char*, ...); +#ifdef __GNUC__ +__attribute__((format(printf, 1, 2))) +#endif extern void exwarn(const char *, ...); extern Extype_t exeval(Expr_t*, Exnode_t*, void*); extern Exnode_t* exexpr(Expr_t*, const char*, Exid_t*, int); -- 2.49.0