summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-03-05 10:09:54 -0800
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-03-05 10:09:54 -0800
commit7ae73442560a50261fe88c5fd5aeceabef9d6b78 (patch)
tree98b4cf45d5cb73e0679bc9fd7939fd933391530b
parent5a848de085e8f2b0458ee7afba5a3d95572f11c2 (diff)
parent1912894f5331a29de37fb13469c6eea16e51d4e4 (diff)
Merge branch 'master' of https://github.com/mloy/pugixml into mloy-master
-rw-r--r--src/pugixml.cpp7
-rw-r--r--tests/test_parse.cpp15
2 files changed, 21 insertions, 1 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index d8a6888..787f693 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -4316,7 +4316,12 @@ 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
- assert(contents || size == 0);
+ if ((contents==NULL) && (size!=0)) {
+ xml_parse_result result;
+ result.status = status_no_document_element;
+ return result;
+ }
+
// 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 321b84c..500e44c 100644
--- a/tests/test_parse.cpp
+++ b/tests/test_parse.cpp
@@ -863,10 +863,25 @@ TEST(parse_declaration_error)
TEST(parse_empty)
{
xml_document doc;
+
CHECK(doc.load_string(STR("")).status == status_no_document_element && !doc.first_child());
CHECK(doc.load_string(STR(""), parse_fragment) && !doc.first_child());
}
+TEST(parse_load_buffer_null)
+{
+ xml_document doc;
+
+ CHECK(doc.load_buffer(0, 12).status == status_no_document_element && !doc.first_child());
+}
+
+TEST(parse_load_buffer_empty)
+{
+ xml_document doc;
+
+ CHECK(doc.load_buffer("foo", 0).status == status_no_document_element);
+}
+
TEST(parse_out_of_memory)
{
test_runner::_memory_fail_threshold = 256;