From 36fb006a34b02bedbfc7f26ac6a35b46bec4ac96 Mon Sep 17 00:00:00 2001 From: Rhodri James Date: Fri, 3 Feb 2017 18:19:56 +0000 Subject: [PATCH] Test XML_SetEncoding against memory allocation failures --- expat/tests/runtests.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index ee94873e..c5947021 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -2554,6 +2554,23 @@ START_TEST(test_alloc_dtd_default_handling) } END_TEST +/* Test robustness of XML_SetEncoding() with a failing allocator */ +START_TEST(test_alloc_explicit_encoding) +{ + int i; + + for (i = 0; i < 5; i++) { + allocation_count = i; + if (XML_SetEncoding(parser, "us-ascii") == XML_STATUS_OK) + break; + } + if (i == 0) + fail("Encoding set despite failing allocator"); + else if (i == 5) + fail("Encoding not set at allocation count 5"); +} +END_TEST + static Suite * make_suite(void) @@ -2655,6 +2672,7 @@ make_suite(void) tcase_add_test(tc_alloc, test_alloc_external_entity); tcase_add_test(tc_alloc, test_alloc_internal_entity); tcase_add_test(tc_alloc, test_alloc_dtd_default_handling); + tcase_add_test(tc_alloc, test_alloc_explicit_encoding); return s; }