From b079debfe85c962d2d6a050a5ab4e2343a5919eb Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sun, 27 Oct 2019 21:20:05 -0400 Subject: [PATCH] debug-info: fix one -Wnull-dereference warning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When building with gcc at -O2, I get: CC debug-info.lo /home/simark/src/babeltrace/src/plugins/lttng-utils/debug-info/debug-info.c: In function ‘debug_info_msg_iter_next’: /home/simark/src/babeltrace/src/plugins/lttng-utils/debug-info/debug-info.c:181:19: error: potential null pointer dereference [-Werror=null-dereference] 181 | bt_logging_level log_level = bin->log_level; | ^~~~~~~~~ Putting a BT_ASSERT(bin) convinces gcc that bin won't be NULL, and if it ever happens to be NULL (because we mess up), the crash will be smoother. This is the last instance of the -Wnull-dereference, so we can remove -Wno-null-dereference from configure.ac. Change-Id: I8bf5c6a0cf231e8516ece14be7b3fcf6f5eaa2ad Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/2270 Reviewed-by: Francis Deslauriers --- configure.ac | 1 - src/plugins/lttng-utils/debug-info/debug-info.c | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 17df88d3..28d247ae 100644 --- a/configure.ac +++ b/configure.ac @@ -677,7 +677,6 @@ AX_COMPILER_FLAGS( -Wno-redundant-decls dnl -Wno-logical-op dnl -Wno-shadow dnl - -Wno-null-dereference dnl -Wno-double-promotion dnl -Wno-cast-align dnl ]) diff --git a/src/plugins/lttng-utils/debug-info/debug-info.c b/src/plugins/lttng-utils/debug-info/debug-info.c index 88f1ccba..7a577042 100644 --- a/src/plugins/lttng-utils/debug-info/debug-info.c +++ b/src/plugins/lttng-utils/debug-info/debug-info.c @@ -178,7 +178,11 @@ struct debug_info_source *debug_info_source_create_from_bin( int ret; struct debug_info_source *debug_info_src = NULL; struct source_location *src_loc = NULL; - bt_logging_level log_level = bin->log_level; + bt_logging_level log_level; + + BT_ASSERT(bin); + + log_level = bin->log_level; debug_info_src = g_new0(struct debug_info_source, 1); -- 2.34.1