]> granicus.if.org Git - libexpat/commitdiff
Test XML_ErrorString range checking
authorRhodri James <rhodri@kynesim.co.uk>
Wed, 8 Feb 2017 14:40:37 +0000 (14:40 +0000)
committerSebastian Pipping <sebastian@pipping.org>
Mon, 13 Mar 2017 17:06:20 +0000 (18:06 +0100)
expat/tests/runtests.c

index d991fc8b82cb444c0be4ae1808daf03703cc96c5..731fcb94550640d2b35695c7b05d4ea244a0a2a4 100644 (file)
@@ -2845,6 +2845,16 @@ START_TEST(test_misc_null_parser)
 }
 END_TEST
 
+/* Test that XML_ErrorString rejects out-of-range codes */
+START_TEST(test_misc_error_string)
+{
+    if (XML_ErrorString((enum XML_Error)-1) != NULL)
+        fail("Negative error code not rejected");
+    if (XML_ErrorString((enum XML_Error)100) != NULL)
+        fail("Large error code not rejected");
+}
+END_TEST
+
 
 static void
 alloc_setup(void)
@@ -3382,6 +3392,7 @@ make_suite(void)
     tcase_add_test(tc_misc, test_misc_alloc_ns);
     tcase_add_test(tc_misc, test_misc_null_parser);
     tcase_add_test(tc_misc, test_misc_alloc_ns_parse_buffer);
+    tcase_add_test(tc_misc, test_misc_error_string);
 
     suite_add_tcase(s, tc_alloc);
     tcase_add_checked_fixture(tc_alloc, alloc_setup, alloc_teardown);