ctf: Fix one -Wnull-dereference warning
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 28 Oct 2019 01:07:35 +0000 (21:07 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 29 Oct 2019 15:35:28 +0000 (11:35 -0400)
commitfba9c0c1d30f57b4e818ad08f2c46233f0451ec4
tree50b3097abaea8092da32153c8e70ed6ff06b26c1
parent8fe10fa82e1ced6204b27d285b3d22db58d1bd06
ctf: Fix one -Wnull-dereference warning

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
This page took 0.026279 seconds and 4 git commands to generate.