From a4fc3dd7705c277e3a57432895e9852ea105dac9 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 7 Oct 2020 17:01:15 +0200 Subject: cmocka: Use intmax_t for assert_return_code() Fixes #31 --- include/cmocka.h | 12 +++++------- src/cmocka.c | 37 +++++++------------------------------ 2 files changed, 12 insertions(+), 37 deletions(-) diff --git a/include/cmocka.h b/include/cmocka.h index 502cc89..1e07c53 100644 --- a/include/cmocka.h +++ b/include/cmocka.h @@ -1048,12 +1048,11 @@ void assert_false(scalar expression); * * @param[in] error Pass errno here or 0. */ -void assert_return_code(int rc, int error); +void assert_return_code(intmax_t rc, int32_t error); #else #define assert_return_code(rc, error) \ - _assert_return_code(cast_to_uintmax_type(rc), \ - sizeof(rc), \ - cast_to_uintmax_type(error), \ + _assert_return_code((rc), \ + (error), \ #rc, __FILE__, __LINE__) #endif @@ -2206,9 +2205,8 @@ void _will_return(const char * const function_name, const char * const file, void _assert_true(const uintmax_t result, const char* const expression, const char * const file, const int line); -void _assert_return_code(const uintmax_t result, - size_t rlen, - const uintmax_t error, +void _assert_return_code(const intmax_t result, + const int32_t error, const char * const expression, const char * const file, const int line); diff --git a/src/cmocka.c b/src/cmocka.c index 479587a..633ba2b 100644 --- a/src/cmocka.c +++ b/src/cmocka.c @@ -1824,41 +1824,18 @@ void _assert_true(const uintmax_t result, } } -void _assert_return_code(const uintmax_t result, - size_t rlen, - const uintmax_t error, +void _assert_return_code(const intmax_t result, + const int32_t error, const char * const expression, const char * const file, const int line) { - uintmax_t valmax; - - - switch (rlen) { - case 1: - valmax = 255; - break; - case 2: - valmax = 32767; - break; - case 4: - valmax = 2147483647; - break; - case 8: - default: - if (rlen > sizeof(valmax)) { - valmax = 2147483647; - } else { - valmax = 9223372036854775807L; - } - break; - } - - if (result > valmax - 1) { + if (result < 0) { if (error > 0) { - cm_print_error("%s < 0, errno(" - UintMaxTypePrintfFormatDecimal "): %s\n", - expression, error, strerror((int)error)); + cm_print_error("%s < 0, errno(%d): %s\n", + expression, + error, + strerror(error)); } else { cm_print_error("%s < 0\n", expression); } -- cgit v1.2.3