debug-info: fix one -Wnull-dereference warning
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 28 Oct 2019 01:20:05 +0000 (21:20 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 30 Oct 2019 19:14:53 +0000 (15:14 -0400)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2270
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
configure.ac
src/plugins/lttng-utils/debug-info/debug-info.c

index 17df88d33123bb378c9073eb693a849085044ea4..28d247ae8ad1453e619cf15c2c537b5435d44856 100644 (file)
@@ -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
        ])
index 88f1ccba0c455063bfbc46f730e2d5e2ad0a9edf..7a57704201b9017062497d525818c16e8decdeed 100644 (file)
@@ -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);
 
This page took 0.026288 seconds and 4 git commands to generate.