From: Michael Jeanson Date: Thu, 30 Jan 2020 16:11:52 +0000 (-0500) Subject: fix: build failure on ppc64el with '-Werror=format-overflow=' X-Git-Tag: v2.0.1~6 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=bee055d7f4d2dbbaca74d4ec40284c3389104764 fix: build failure on ppc64el with '-Werror=format-overflow=' 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 Change-Id: Ia727b37b04cb10f29e705f21c6889035a304a822 Reviewed-on: https://review.lttng.org/c/babeltrace/+/2894 Reviewed-by: Simon Marchi Tested-by: jenkins --- diff --git a/src/lib/plugin/plugin-so.c b/src/lib/plugin/plugin-so.c index 46a50630..06c0b634 100644 --- a/src/lib/plugin/plugin-so.c +++ b/src/lib/plugin/plugin-so.c @@ -176,7 +176,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."); @@ -220,7 +220,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;