diff --git a/test/test-xml.c b/test/test-xml.c index ccee27e..de08c6d 100644 --- a/test/test-xml.c +++ b/test/test-xml.c @@ -76,9 +76,9 @@ static _Bool string_equals(struct xml_string* a, char const* b) { * Converts a static character array to an uint8_t data source */ #define SOURCE(source, content) \ - uint8_t* source = alloca(strlen(content) * sizeof(uint8_t)); \ + uint8_t* source = calloc(strlen(content) + 1, sizeof(uint8_t)); \ { char const* content_string = content; \ - memcpy(source, content_string, strlen(content)); \ + memcpy(source, content_string, strlen(content) + 1); \ } @@ -88,6 +88,10 @@ static _Bool string_equals(struct xml_string* a, char const* b) { */ static void test_xml_parse_document_0() { SOURCE(source, "World"); +// uint8_t* source = malloc((1 + strlen("World")) * sizeof(uint8_t)); +// { char const* content_string = "World"; +// memcpy(source, content_string, strlen("World") + 1); +// } struct xml_document* document = xml_parse_document(source, strlen(source)); assert_that(document, "Could not parse document"); @@ -96,7 +100,7 @@ static void test_xml_parse_document_0() { assert_that(string_equals(xml_node_name(root), "Hello"), "root node name must be `Hello'"); assert_that(string_equals(xml_node_content(root), "World"), "root node content must be `World'"); - xml_document_free(document, false); + xml_document_free(document, true); } /** @@ -132,7 +136,7 @@ static void test_xml_parse_document_1() { assert_that(string_equals(xml_node_name(second_child), "Child"), "second_child node name must be `Child'"); assert_that(string_equals(xml_node_content(second_child), "Second content"), "second_child node content must be `tSecond content'"); - xml_document_free(document, false); + xml_document_free(document, true); }