ctf: fix -Wformat-overflow error in ctf-meta-resolve.cpp
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 23 Feb 2023 19:19:10 +0000 (14:19 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 13 Mar 2023 15:26:10 +0000 (11:26 -0400)
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 <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
(cherry picked from commit ceda1ae6ecf09cd6ad521b34b553f78dbe9bec21)
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9548
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/plugins/ctf/common/metadata/ctf-meta-resolve.c

index bc303c15c171b30163707de354ec85fa0351e3f8..5233ef64562a890670d9ecfd5a6cfd8b686f313e 100644 (file)
@@ -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\"",
This page took 0.025808 seconds and 4 git commands to generate.