From 10092717214dcb9b440c8062ecb702a41e8dd8ce Mon Sep 17 00:00:00 2001 From: Omar Sandoval Date: Mon, 9 Oct 2023 14:01:23 -0700 Subject: [PATCH] libdrgn: mark log format as non-NULL and disable -Wformat-zero-length In my branch for the module API (#332), I want to log an error without any additional context. Passing an empty format string causes a "zero-length gnu_printf format string" warning from GCC, and passing NULL crashes in vsnprintf(). Empty format strings are totally valid, but NULL clearly isn't, so annotate the format parameter as non-NULL and disable -Wformat-zero-length. Signed-off-by: Omar Sandoval --- libdrgn/configure.ac | 1 + libdrgn/log.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libdrgn/configure.ac b/libdrgn/configure.ac index efd457415..1faa2a631 100644 --- a/libdrgn/configure.ac +++ b/libdrgn/configure.ac @@ -113,6 +113,7 @@ AS_IF([test "x$enable_compiler_warnings" != xno], -Wimplicit-fallthrough dnl -Wmissing-prototypes dnl -Wvla dnl + -Wno-format-zero-length dnl ], [WARN_CFLAGS], [$compiler_flags_test])]) AS_IF([test "x$enable_compiler_warnings" = xerror], [AX_APPEND_FLAG([-Werror], [WARN_CFLAGS])]) diff --git a/libdrgn/log.h b/libdrgn/log.h index 74085afc8..1414eca23 100644 --- a/libdrgn/log.h +++ b/libdrgn/log.h @@ -67,7 +67,7 @@ void drgn_log(enum drgn_log_level level, struct drgn_program *prog, /** * Log a printf-style message followed by a @ref drgn_error at the given level. */ -__attribute__((__format__(__printf__, 4, 5))) +__attribute__((__format__(__printf__, 4, 5), __nonnull__(2, 4))) void drgn_error_log(enum drgn_log_level level, struct drgn_program *prog, struct drgn_error *err, const char *format, ...); /** Log a critical message followed by a @ref drgn_error. */