ctf: Fix one -Wnull-dereference warning
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 28 Oct 2019 01:07:35 +0000 (21:07 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 30 Oct 2019 19:14:53 +0000 (15:14 -0400)
When building at -O2 with gcc, I get:

      CC       visitor-generate-ir.lo
    /home/simark/src/babeltrace/src/plugins/ctf/common/metadata/visitor-generate-ir.c: In function ‘auto_map_fields_to_trace_clock_class’:
    /home/simark/src/babeltrace/src/plugins/ctf/common/metadata/visitor-generate-ir.c:3498:22: error: potential null pointer dereference [-Werror=null-dereference]
     3498 |   if (strcmp(named_fc->name->str, field_name) == 0) {
          |              ~~~~~~~~^~~~~~

Purely based on control flow analysis, named_fc could be NULL at this
point if none of the conditional branches above are taken.  It's
logically not supposed to happen, unless in case of a programming error
on our part.

We can silence this warning and indicate that this would be an abnormal
situation by aborting if root_fc->type is neither
CTF_FIELD_CLASS_TYPE_STRUCT nor CTF_FIELD_CLASS_TYPE_VARIANT.

Change-Id: I3c5ffefc2f15c56cbc73311ffdb1e0bd2dc66243
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2269
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
src/plugins/ctf/common/metadata/visitor-generate-ir.c

index 99d6ae4c83de8ef320a4413a4cce74b939a445de..11cb3c3d21045572a6a9d20372b2c31d9db0b426 100644 (file)
@@ -3493,6 +3493,8 @@ int auto_map_fields_to_trace_clock_class(struct ctx *ctx,
                } else if (root_fc->type == CTF_FIELD_CLASS_TYPE_VARIANT) {
                        named_fc = ctf_field_class_variant_borrow_option_by_index(
                                var_fc, i);
+               } else {
+                       abort();
                }
 
                if (strcmp(named_fc->name->str, field_name) == 0) {
This page took 0.026373 seconds and 4 git commands to generate.