From 25f039fc5b6f119ccbd868f032be576a900335ce Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 23 Feb 2023 14:19:10 -0500 Subject: [PATCH] ctf: fix -Wformat-overflow error in ctf-meta-resolve.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fix this, seen when building with -O2 with gcc 12.2.1: CXX ctf-meta-resolve.lo In file included from ../../../../../src/logging/comp-logging.h:16, from ctf-meta-resolve.cpp:12: In function 'int pathstr_to_field_path(const char*, ctf_field_path*, resolve_context*)', inlined from 'int resolve_sequence_or_variant_field_class(ctf_field_class*, resolve_context*)' at ctf-meta-resolve.cpp:948:32, inlined from 'int resolve_field_class(ctf_field_class*, resolve_context*)' at ctf-meta-resolve.cpp:1026:54: ../../../../../src/logging/comp-logging.h:18:41: error: '%s' directive argument is null [-Werror=format-overflow=] 18 | #define _BT_COMP_LOG_COMP_PREFIX "[%s] " ../../../../../src/logging/log.h:815:67: note: in definition of macro 'BT_LOG_WRITE' 815 | lvl, tag, __VA_ARGS__); \ | ^~~~~~~~~~~ ../../../../../src/logging/comp-logging.h:23:42: note: in expansion of macro '_BT_COMP_LOG_COMP_PREFIX' 23 | BT_LOG_WRITE((_lvl), BT_LOG_TAG, _BT_COMP_LOG_COMP_PREFIX _fmt, \ | ^~~~~~~~~~~~~~~~~~~~~~~~ ../../../../../src/logging/comp-logging.h:83:9: note: in expansion of macro 'BT_COMP_LOG' 83 | BT_COMP_LOG(BT_LOG_DEBUG, (BT_COMP_LOG_SELF_COMP), _fmt, ##__VA_ARGS__) | ^~~~~~~~~~~ ctf-meta-resolve.cpp:650:9: note: in expansion of macro 'BT_COMP_LOGD' 650 | BT_COMP_LOGD("Found field path: path=\"%s\", field-path=\"%s\"", pathstr, | ^~~~~~~~~~~~ Change-Id: Ib311185359a531f3e14bfbbbe6726aa633ceb3e4 Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau (cherry picked from commit ceda1ae6ecf09cd6ad521b34b553f78dbe9bec21) Reviewed-on: https://review.lttng.org/c/babeltrace/+/9548 Reviewed-by: Philippe Proulx --- src/plugins/ctf/common/metadata/ctf-meta-resolve.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/ctf/common/metadata/ctf-meta-resolve.c b/src/plugins/ctf/common/metadata/ctf-meta-resolve.c index bc303c15..5233ef64 100644 --- a/src/plugins/ctf/common/metadata/ctf-meta-resolve.c +++ b/src/plugins/ctf/common/metadata/ctf-meta-resolve.c @@ -681,7 +681,7 @@ int pathstr_to_field_path(const char *pathstr, if (BT_LOG_ON_TRACE && ret == 0) { GString *field_path_pretty = 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_COMP_LOGD("Found field path: path=\"%s\", field-path=\"%s\"", pathstr, field_path_pretty_str); @@ -774,9 +774,9 @@ int64_t get_field_paths_lca_index(struct ctf_field_path *field_path1, GString *field_path2_pretty = 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_COMP_LOGD("Finding lowest common ancestor (LCA) between two field paths: " "field-path-1=\"%s\", field-path-2=\"%s\"", -- 2.34.1