From 9749920c8204930f868fed7fcf38ea2cc2b5a2ec Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 5 Mar 2015 11:35:39 -0800 Subject: Refactor contents=0 behavior Also change the error code to status_io_error --- src/pugixml.cpp | 7 +------ tests/test_parse.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 787f693..fa41058 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -4316,12 +4316,7 @@ PUGI__NS_BEGIN PUGI__FN xml_parse_result load_buffer_impl(xml_document_struct* doc, xml_node_struct* root, void* contents, size_t size, unsigned int options, xml_encoding encoding, bool is_mutable, bool own, char_t** out_buffer) { // check input buffer - if ((contents==NULL) && (size!=0)) { - xml_parse_result result; - result.status = status_no_document_element; - return result; - } - + if (!contents && size) return make_parse_result(status_io_error); // get actual encoding xml_encoding buffer_encoding = impl::get_buffer_encoding(encoding, contents, size); diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp index 500e44c..131840c 100644 --- a/tests/test_parse.cpp +++ b/tests/test_parse.cpp @@ -872,14 +872,16 @@ TEST(parse_load_buffer_null) { xml_document doc; - CHECK(doc.load_buffer(0, 12).status == status_no_document_element && !doc.first_child()); + CHECK(doc.load_buffer(0, 12).status == status_io_error && !doc.first_child()); + CHECK(doc.load_buffer(0, 12, parse_fragment).status == status_io_error && !doc.first_child()); } TEST(parse_load_buffer_empty) { xml_document doc; - CHECK(doc.load_buffer("foo", 0).status == status_no_document_element); + CHECK(doc.load_buffer("foo", 0).status == status_no_document_element && !doc.first_child()); + CHECK(doc.load_buffer("foo", 0, parse_fragment) && !doc.first_child()); } TEST(parse_out_of_memory) -- cgit v1.2.3