diff options
author | Wolfram Rösler <wolfram.roesler@devolo.de> | 2020-11-26 08:59:27 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2021-01-13 17:29:35 +0100 |
commit | 65d69f72b8ce0f6f4b29f41f21cccdbfaba7f722 (patch) | |
tree | 938341dfed19d15ada498038f554a46cf269414a /src/cmocka.c | |
parent | a4fc3dd7705c277e3a57432895e9852ea105dac9 (diff) | |
download | cmocka-65d69f72b8ce0f6f4b29f41f21cccdbfaba7f722.tar.gz cmocka-65d69f72b8ce0f6f4b29f41f21cccdbfaba7f722.tar.xz cmocka-65d69f72b8ce0f6f4b29f41f21cccdbfaba7f722.zip |
Fix unexpanded %s in leftover values error messages
Before:
myfunction: '%s' parameter still has values that haven't been checked.
Now, %s is expanded properly:
myfunction: 'num_samples' parameter still has values that haven't been checked.
Parameter `error_message` of functions `check_for_leftover_values` and
`check_for_leftover_values_list` isn't actually the error message but
rather a printf-style format string (containing one `%s`) used to build
the error message. That means that it must be the first argument of
`cm_print_error`. The previous version used another `%s` to output the
contents of `error_message`, so the format string was printed but not
expanded.
Renamed the parameter to `error_message_fmt` for emphasis.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/cmocka.c')
-rw-r--r-- | src/cmocka.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/cmocka.c b/src/cmocka.c index 633ba2b..956763f 100644 --- a/src/cmocka.c +++ b/src/cmocka.c @@ -267,10 +267,10 @@ static void remove_always_return_values(ListNode * const map_head, const size_t number_of_symbol_names); static size_t check_for_leftover_values_list(const ListNode * head, - const char * const error_message); + const char * const error_message_fmt); static size_t check_for_leftover_values( - const ListNode * const map_head, const char * const error_message, + const ListNode * const map_head, const char * const error_message_fmt, const size_t number_of_symbol_names); static void remove_always_return_values_from_list(ListNode * const map_head); @@ -917,7 +917,7 @@ static void remove_always_return_values(ListNode * const map_head, } static size_t check_for_leftover_values_list(const ListNode * head, - const char * const error_message) + const char * const error_message_fmt) { ListNode *child_node; size_t leftover_count = 0; @@ -927,7 +927,7 @@ static size_t check_for_leftover_values_list(const ListNode * head, child_node = child_node->next, ++leftover_count) { const FuncOrderingValue *const o = (const FuncOrderingValue*) child_node->value; - cm_print_error("%s: %s", error_message, o->function); + cm_print_error(error_message_fmt, o->function); cm_print_error(SOURCE_LOCATION_FORMAT ": note: remaining item was declared here\n", o->location.file, o->location.line); @@ -941,7 +941,7 @@ static size_t check_for_leftover_values_list(const ListNode * head, * retrieved through execution, and fail the test if that is the case. */ static size_t check_for_leftover_values( - const ListNode * const map_head, const char * const error_message, + const ListNode * const map_head, const char * const error_message_fmt, const size_t number_of_symbol_names) { const ListNode *current; size_t symbols_with_leftover_values = 0; @@ -959,7 +959,7 @@ static size_t check_for_leftover_values( if (!list_empty(child_list)) { if (number_of_symbol_names == 1) { const ListNode *child_node; - cm_print_error("%s: %s", error_message, value->symbol_name); + cm_print_error(error_message_fmt, value->symbol_name); for (child_node = child_list->next; child_node != child_list; child_node = child_node->next) { @@ -971,7 +971,7 @@ static size_t check_for_leftover_values( } } else { cm_print_error("%s: ", value->symbol_name); - check_for_leftover_values(child_list, error_message, + check_for_leftover_values(child_list, error_message_fmt, number_of_symbol_names - 1); } symbols_with_leftover_values ++; |