cmocka: fix setjmp in expect_assert_failure macro

Assigning the result of `setjmp` to a variable is technically
undefined behavior in the C standard.

Most platforms allow this (NetBSD even uses this syntax in their tests)
and GCC/Clang doesn't even give us a warning. Nonetheless, we should
follow the ISO C specification.

See [§ 7.13.1.1.4 of the C99 spec.][1]

[1]: https://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf
on-behalf-of: @nqminds <info@nqminds.com>

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Alois Klink 2022-12-19 19:18:02 +00:00 committed by Andreas Schneider
parent b78067e0c1
commit 57234cdef3
1 changed files with 1 additions and 2 deletions

View File

@ -2314,9 +2314,8 @@ void expect_assert_failure(function fn_call);
#else
#define expect_assert_failure(function_call) \
{ \
const int result = setjmp(global_expect_assert_env); \
global_expecting_assert = 1; \
if (result) { \
if (setjmp(global_expect_assert_env) != 0) { \
print_message("Expected assertion %s occurred\n", \
global_last_failed_assert); \
global_expecting_assert = 0; \