Fix: lib: pass down API function name to some helpers
authorSimon Marchi <simon.marchi@efficios.com>
Sun, 8 May 2022 01:42:36 +0000 (21:42 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 10 May 2022 13:46:03 +0000 (09:46 -0400)
commit867eb7632255f6a84234542198bd7edaac1bce12
treee55b0ec990532aeed07ef75a5f9453c00997e849
parent76edbcf1a675fe2d7d058c1b3ae1bd6fbe073e1c
Fix: lib: pass down API function name to some helpers

Let's say I change bt_field_structure_borrow_member_field_by_index to
pass an invalid index (e.g. 99999) to
borrow_structure_field_member_field_by_index, to exercise the "valid
index" precondition assertion, I get:

   (╯°□°)╯︵ ┻━┻  /home/simark/src/babeltrace/src/lib/assert-cond.c:33: format_cond_id(): Assertion `strstr(func, func_prefix) == func` failed.

This is because `format_cond_id` expects to receive the name of the API
function called by the user, starting with `bt_`.  But it's the name of
the `borrow_structure_field_member_field_by_index` helper that is passed
down to `format_cond_id`, instead.

Change some helpers in lib/trace-ir/field.c to pass down the API
function name to their helper, to avoid this.  Add some necessary
"FROM_FUNC" version of assertions used by these helpers.

Introducing the same "bug", I get the expected precondition assertion
failure message:

    05-07 21:54:06.709 2194353 2194353 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:65 Babeltrace 2 library precondition not satisfied.
    05-07 21:54:06.709 2194353 2194353 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:66 ------------------------------------------------------------------------
    05-07 21:54:06.709 2194353 2194353 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:67 Condition ID: `pre:field-structure-borrow-member-field-by-index:valid-index`.
    05-07 21:54:06.709 2194353 2194353 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:69 Function: bt_field_structure_borrow_member_field_by_index().
    05-07 21:54:06.709 2194353 2194353 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:70 ------------------------------------------------------------------------
    05-07 21:54:06.709 2194353 2194353 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:71 Error is:
    05-07 21:54:06.709 2194353 2194353 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:73 Index is out of bounds: index=99999, count=1
    05-07 21:54:06.709 2194353 2194353 F LIB/ASSERT-COND bt_lib_assert_cond_failed@assert-cond.c:76 Aborting...

Change-Id: Id3c310a3c5c46358532657d38d867c5ed802df78
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8002
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>
src/lib/assert-cond.h
src/lib/trace-ir/field.c
This page took 0.034624 seconds and 4 git commands to generate.