mirror of
https://github.com/libexpat/libexpat.git
synced 2025-04-13 08:02:56 +00:00
tests/misc_tests.c: Address clang-tidy 18 warning EnumCastOutOfRange
clang-tidy output was: > [..]/libexpat/expat/tests/misc_tests.c:112:23: note: The value '-1' provided to the cast expression is not in the valid range of values for 'XML_Error' > 112 | if (XML_ErrorString((enum XML_Error) - 1) != NULL) > | ^~~~~~~~~~~~~~~~~~~~ > [..]/libexpat/expat/tests/misc_tests.c:114:23: error: The value '100' provided to the cast expression is not in the valid range of values for 'XML_Error' [clang-analyzer-optin.core.EnumCastOutOfRange,-warnings-as-errors] > 114 | if (XML_ErrorString((enum XML_Error)100) != NULL) > | ^~~~~~~~~~~~~~~~~~~
This commit is contained in:
parent
abd9542b32
commit
737e8ea183
1 changed files with 24 additions and 2 deletions
|
@ -107,12 +107,34 @@ START_TEST(test_misc_null_parser) {
|
|||
}
|
||||
END_TEST
|
||||
|
||||
#if defined(__has_feature)
|
||||
# if __has_feature(undefined_behavior_sanitizer)
|
||||
# define EXPAT_TESTS_UBSAN 1
|
||||
# else
|
||||
# define EXPAT_TESTS_UBSAN 0
|
||||
# endif
|
||||
#else
|
||||
# define EXPAT_TESTS_UBSAN 0
|
||||
#endif
|
||||
|
||||
/* Test that XML_ErrorString rejects out-of-range codes */
|
||||
START_TEST(test_misc_error_string) {
|
||||
if (XML_ErrorString((enum XML_Error) - 1) != NULL)
|
||||
#if ! EXPAT_TESTS_UBSAN // because this would trigger UBSan
|
||||
union {
|
||||
enum XML_Error xml_error;
|
||||
int integer;
|
||||
} trickery;
|
||||
|
||||
assert_true(sizeof(enum XML_Error) == sizeof(int)); // self-test
|
||||
|
||||
trickery.integer = -1;
|
||||
if (XML_ErrorString(trickery.xml_error) != NULL)
|
||||
fail("Negative error code not rejected");
|
||||
if (XML_ErrorString((enum XML_Error)100) != NULL)
|
||||
|
||||
trickery.integer = 100;
|
||||
if (XML_ErrorString(trickery.xml_error) != NULL)
|
||||
fail("Large error code not rejected");
|
||||
#endif
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue