ctf: avoid using computing offset from nullptr pointer
authorSimon Marchi <simon.marchi@efficios.com>
Sat, 18 Feb 2023 02:17:15 +0000 (21:17 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 7 Mar 2023 16:23:40 +0000 (11:23 -0500)
When running the test_trace_collection_message_iterator.py test in a
build with -fsanitize=undefined, I see:

  /home/simark/src/babeltrace/src/plugins/ctf/common/metadata/visitor-generate-ir.cpp:1143:30: runtime error: member access within null pointer of type 'struct ctf_node'

This happens when `node_field_class_declarator` is nullptr.  Avoid this
by using `node_field_class_declarator` once we know it's non-nullptr.

Change-Id: I585e5b17af7e1a16a217ef46c0a49fae901dcae8
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9513
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/plugins/ctf/common/metadata/visitor-generate-ir.cpp

index a55cbc375fb20d4b9b6dbeb8eff84c8123b31102..33fa1ccb3a2b076aa2cc80ccb86f06da19bfa8a7 100644 (file)
@@ -1127,10 +1127,8 @@ static int visit_field_class_declarator(struct ctf_visitor_generate_ir *ctx,
 
     /* Find the right nested declaration if not provided */
     if (!nested_decl) {
-        struct bt_list_head *pointers =
-            &node_field_class_declarator->u.field_class_declarator.pointers;
-
-        if (node_field_class_declarator && !bt_list_empty(pointers)) {
+        if (node_field_class_declarator &&
+            !bt_list_empty(&node_field_class_declarator->u.field_class_declarator.pointers)) {
             GQuark qalias;
 
             /*
This page took 0.027167 seconds and 4 git commands to generate.