Skip to content

Commit

Permalink
libdrgn: mark log format as non-NULL and disable -Wformat-zero-length
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
osandov committed Oct 9, 2023
1 parent aefe704 commit 1009271
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions libdrgn/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])])
Expand Down
2 changes: 1 addition & 1 deletion libdrgn/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit 1009271

Please sign in to comment.