From 776c56bd7e1699b3d8cd22fc19808a985435e217 Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Wed, 16 Oct 2024 12:26:54 -0700 Subject: [PATCH] Fix compiler warnings about format specifiers with DEBUG set As for %s when the pointer is null: even if gcc prints (null) this is still undefined behavior, so we should do this explicitly Signed-off-by: Ryan Lee --- parser/parser_interface.c | 2 +- parser/parser_yacc.y | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/parser/parser_interface.c b/parser/parser_interface.c index 816fe5cba..357d55239 100644 --- a/parser/parser_interface.c +++ b/parser/parser_interface.c @@ -245,7 +245,7 @@ static inline void sd_write_uint64(std::ostringstream &buf, u64 b) static inline void sd_write_name(std::ostringstream &buf, const char *name) { - PDEBUG("Writing name '%s'\n", name); + PDEBUG("Writing name '%s'\n", name ? name : "(null)"); if (name) { sd_write8(buf, SD_NAME); sd_write16(buf, strlen(name) + 1); diff --git a/parser/parser_yacc.y b/parser/parser_yacc.y index 532ddb55a..7bc5067ef 100644 --- a/parser/parser_yacc.y +++ b/parser/parser_yacc.y @@ -704,7 +704,7 @@ rules: rules opt_prefix block if (($2).priority != 0) { yyerror(_("priority is not allowed on rule blocks")); } - PDEBUG("matched: %s%s%sblock\n", + PDEBUG("matched: %s%s%s%sblock\n", $2.audit == AUDIT_FORCE ? "audit " : "", $2.rule_mode == RULE_DENY ? "deny " : "", $2.rule_mode == RULE_PROMPT ? "prompt " : "",