From 1e0116a4a8bb71a06e145fd5d5b294364e9f3678 Mon Sep 17 00:00:00 2001 From: Sergio Durigan Junior Date: Wed, 6 May 2026 07:54:39 -0400 Subject: [PATCH] misc_test.c: Workaround GCC 16's Wstringop-overread error Due to the way `cjson_set_valuestring_should_return_null_if_strings_overlap` is constructed, GCC determines that `str` will have a size of 0 after the second `cJSON_SetValuestring` call. Just ignore the warning in this specific case as it is a false positive. Fixes #1016 --- tests/misc_tests.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/misc_tests.c b/tests/misc_tests.c index fe2325e9..07f387ea 100644 --- a/tests/misc_tests.c +++ b/tests/misc_tests.c @@ -502,7 +502,12 @@ static void cjson_set_valuestring_should_return_null_if_strings_overlap(void) /* The string passed to strcpy overlap which is not allowed.*/ str2 = cJSON_SetValuestring(obj, str); /* If it overlaps, the string will be messed up.*/ +#if defined(__GNUC__) && (__GNUC__ >= 16) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overread" TEST_ASSERT_TRUE(strcmp(str, "bcde") == 0); +#pragma GCC diagnostic pop +#endif TEST_ASSERT_NULL(str2); cJSON_Delete(obj); }