From bce86460fe197b2766262389552d468f7cd55832 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Mon, 18 Jan 2021 18:16:05 +0100 Subject: [PATCH] Rewrite test cases to avoid potential warnings --- tests/test-mcore.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/test-mcore.c b/tests/test-mcore.c index 249d24a3..7ce0768f 100644 --- a/tests/test-mcore.c +++ b/tests/test-mcore.c @@ -611,12 +611,26 @@ static void test_str_hash(void) static void test_M_CSTR(void) { - assert ( strcmp(M_CSTR("Len=%d", 17), "Len=17") == 0); - assert ( strcmp(M_CSTR("Hello %s %c", "World", '!'), "Hello World !") == 0); + int r; + r = strcmp(M_CSTR("Len=%d", 17), "Len=17"); + assert (r == 0); + r = strcmp(M_CSTR("Hello %s %c", "World", '!'), "Hello World !"); + assert (r == 0); + // Reduce allocation to test truncation #undef M_USE_CSTR_ALLOC #define M_USE_CSTR_ALLOC 8 - assert ( strcmp(M_CSTR("Hello %s %c", "World", '!'), "Hello W") == 0); + // Disable GNUC warning as we want to test this behavior. + // this warning is not supported by CLANG +#if defined (__GNUC__) && __GNUC__ >= 7 && !defined(__clang__) + _Pragma("GCC diagnostic push") + _Pragma("GCC diagnostic ignored \"-Wformat-truncation\"") +#endif + r = strcmp(M_CSTR("Hello %s %c", "World", '!'), "Hello W"); +#ifdef __GNUC__ + _Pragma("GCC diagnostic pop") +#endif + assert (r == 0); } int main(void)