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>
} 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) {