fix: build failure on ppc64el with '-Werror=format-overflow='
authorMichael Jeanson <mjeanson@efficios.com>
Thu, 30 Jan 2020 16:11:52 +0000 (11:11 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 30 Jan 2020 19:01:30 +0000 (14:01 -0500)
Enabling optimizations makes gcc inline bt_plugin_so_shared_lib_handle_create
into bt_plugin_so_create_all_from_static.  That call site passes path == NULL,
so gcc notices that the argument to %s will always be NULL. This is
undefined behavior even if glibc will print "(null)".

Passing NULL to this function just means that we are loading the static
plugins, built-in Babeltrace.  So there's no path to a shared object file,
in this case explicitly print "(null)".

In file included from ../../../src/lib/logging.h:35,
                 from plugin-so.c:27:
In function ‘bt_plugin_so_shared_lib_handle_create’,
    inlined from ‘bt_plugin_so_create_all_from_static’ at plugin-so.c:1393:11:
../../../src/logging/log.h:811:6: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
  811 |      _bt_log_write_d(_BT_LOG_SRCLOC_FUNCTION, __FILE__, __LINE__, \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  812 |        lvl, tag, __VA_ARGS__); \
      |        ~~~~~~~~~~~~~~~~~~~~~~
../../../src/logging/log.h:897:4: note: in expansion of macro ‘BT_LOG_WRITE’
  897 |    BT_LOG_WRITE(BT_LOG_INFO, _BT_LOG_TAG, __VA_ARGS__)
      |    ^~~~~~~~~~~~
plugin-so.c:174:2: note: in expansion of macro ‘BT_LOGI’
  174 |  BT_LOGI("Creating shared library handle: path=\"%s\"", path);
      |  ^~~~~~~
plugin-so.c: In function ‘bt_plugin_so_create_all_from_static’:
plugin-so.c:174:50: note: format string is defined here
  174 |  BT_LOGI("Creating shared library handle: path=\"%s\"", path);
      |                                                  ^~
In file included from ../../../src/lib/logging.h:35,
                 from plugin-so.c:27:
In function ‘bt_plugin_so_shared_lib_handle_create’,
    inlined from ‘bt_plugin_so_create_all_from_static’ at plugin-so.c:1393:11:
../../../src/logging/log.h:811:6: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
  811 |      _bt_log_write_d(_BT_LOG_SRCLOC_FUNCTION, __FILE__, __LINE__, \
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  812 |        lvl, tag, __VA_ARGS__); \
      |        ~~~~~~~~~~~~~~~~~~~~~~
../../../src/logging/log.h:897:4: note: in expansion of macro ‘BT_LOG_WRITE’
  897 |    BT_LOG_WRITE(BT_LOG_INFO, _BT_LOG_TAG, __VA_ARGS__)
      |    ^~~~~~~~~~~~
plugin-so.c:217:3: note: in expansion of macro ‘BT_LOGI’
  217 |   BT_LOGI("Created shared library handle: path=\"%s\", addr=%p",
      |   ^~~~~~~
plugin-so.c: In function ‘bt_plugin_so_create_all_from_static’:
plugin-so.c:217:50: note: format string is defined here
  217 |   BT_LOGI("Created shared library handle: path=\"%s\", addr=%p",
      |                                                  ^~
cc1: all warnings being treated as errors

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Change-Id: Ia727b37b04cb10f29e705f21c6889035a304a822
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2894
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
src/lib/plugin/plugin-so.c

index 3684acaedd930fa5b3948a375cb54d1c3067b6b2..be4fc428b2147ee78d7ad55a398187a384240c0a 100644 (file)
@@ -171,7 +171,7 @@ int bt_plugin_so_shared_lib_handle_create(
        int status = BT_FUNC_STATUS_OK;
 
        BT_ASSERT(shared_lib_handle);
-       BT_LOGI("Creating shared library handle: path=\"%s\"", path);
+       BT_LOGI("Creating shared library handle: path=\"%s\"", path ? path : "(null)");
        *shared_lib_handle = g_new0(struct bt_plugin_so_shared_lib_handle, 1);
        if (!*shared_lib_handle) {
                BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one shared library handle.");
@@ -215,7 +215,7 @@ end:
        BT_ASSERT(*shared_lib_handle || status != BT_FUNC_STATUS_OK);
        if (*shared_lib_handle) {
                BT_LOGI("Created shared library handle: path=\"%s\", addr=%p",
-                       path, *shared_lib_handle);
+                       path ? path : "(null)", *shared_lib_handle);
        }
 
        return status;
This page took 0.025947 seconds and 4 git commands to generate.