From 39630c3ba7000fc6c9337b2420bbeba2d9d7c723 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 23 Feb 2023 14:11:38 -0500 Subject: [PATCH] ctf-writer: fix -Wformat-overflow errors in resolve.c MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fix these, seen when building with -O2 with gcc 12.2.1: CC resolve.lo In file included from logging.h:11, from resolve.c:11: In function 'pathstr_to_field_path', inlined from 'resolve_sequence_or_variant_type' at resolve.c:1004:22, inlined from 'resolve_type' at resolve.c:1105:9: resolve.c:667:25: error: '%s' directive argument is null [-Werror=format-overflow=] 667 | BT_LOGT("Found field path: path=\"%s\", field-path=\"%s\"", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/logging/log.h:815:67: note: in definition of macro 'BT_LOG_WRITE' 815 | lvl, tag, __VA_ARGS__); \ | ^~~~~~~~~~~ resolve.c:667:17: note: in expansion of macro 'BT_LOGT' 667 | BT_LOGT("Found field path: path=\"%s\", field-path=\"%s\"", | ^~~~~~~ resolve.c: In function 'resolve_type': resolve.c:667:70: note: format string is defined here 667 | BT_LOGT("Found field path: path=\"%s\", field-path=\"%s\"", | ^~ In function 'get_field_paths_lca_index', inlined from 'validate_target_field_path' at resolve.c:901:15, inlined from 'resolve_sequence_or_variant_type' at resolve.c:1026:8, inlined from 'resolve_type' at resolve.c:1105:9: resolve.c:792:25: error: '%s' directive argument is null [-Werror=format-overflow=] 792 | BT_LOGT("Finding lowest common ancestor (LCA) between two field paths: " | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/logging/log.h:815:67: note: in definition of macro 'BT_LOG_WRITE' 815 | lvl, tag, __VA_ARGS__); \ | ^~~~~~~~~~~ resolve.c:792:17: note: in expansion of macro 'BT_LOGT' 792 | BT_LOGT("Finding lowest common ancestor (LCA) between two field paths: " | ^~~~~~~ resolve.c:792:25: error: '%s' directive argument is null [-Werror=format-overflow=] 792 | BT_LOGT("Finding lowest common ancestor (LCA) between two field paths: " | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/logging/log.h:815:67: note: in definition of macro 'BT_LOG_WRITE' 815 | lvl, tag, __VA_ARGS__); \ | ^~~~~~~~~~~ resolve.c:792:17: note: in expansion of macro 'BT_LOGT' 792 | BT_LOGT("Finding lowest common ancestor (LCA) between two field paths: " | ^~~~~~~ Change-Id: I91608a4e782a4059225986dd974130ccbaf54207 Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau --- src/ctf-writer/resolve.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ctf-writer/resolve.c b/src/ctf-writer/resolve.c index c6316c0b..6db0fb4a 100644 --- a/src/ctf-writer/resolve.c +++ b/src/ctf-writer/resolve.c @@ -662,7 +662,7 @@ struct bt_ctf_field_path *pathstr_to_field_path(const char *pathstr, GString *field_path_pretty = bt_ctf_field_path_string(field_path); const char *field_path_pretty_str = - field_path_pretty ? field_path_pretty->str : NULL; + field_path_pretty ? field_path_pretty->str : "(null)"; BT_LOGT("Found field path: path=\"%s\", field-path=\"%s\"", pathstr, field_path_pretty_str); @@ -785,9 +785,9 @@ int get_field_paths_lca_index(struct bt_ctf_field_path *field_path1, GString *field_path2_pretty = bt_ctf_field_path_string(field_path2); const char *field_path1_pretty_str = - field_path1_pretty ? field_path1_pretty->str : NULL; + field_path1_pretty ? field_path1_pretty->str : "(null)"; const char *field_path2_pretty_str = - field_path2_pretty ? field_path2_pretty->str : NULL; + field_path2_pretty ? field_path2_pretty->str : "(null)"; BT_LOGT("Finding lowest common ancestor (LCA) between two field paths: " "field-path-1=\"%s\", field-path-2=\"%s\"", -- 2.34.1