ctf, ctf-writer: Fix -Wnull-dereference warnings
When building at the -O2 optimization level with gcc, I get this:
/home/simark/src/babeltrace/src/ctf-writer/resolve.c: In function ‘resolve_type’:
/home/simark/src/babeltrace/src/ctf-writer/resolve.c:541:7: error: potential null pointer dereference [-Werror=null-dereference]
541 | int cur_index = type_stack_at(ctx->type_stack,
| ^~~~~~~~~
gcc sees that type_stack_at can possibly return NULL, but we dereference
it unconditionally. All callers of type_stack_at don't check NULL, so
that is a good sign that it never happens. From what I understand, if
it were to happen it would be a programming error, not a legitimate
error. So I think we can simplify this code by making it a precondition
of calling type_stack_at that `stack` should not be NULL and `index`
should represent a valid element of `stack`. This gets rid of the
warning at the same time.
There is the same pattern in the ctf plugin code, so fix it there too.
Change-Id: I82a7cdf74ea987a597cdf219346ec3b36e8ab200
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2268
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
This page took 0.025362 seconds and 4 git commands to generate.