File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -264,7 +264,7 @@ PUGI_IMPL_NS_BEGIN
264
264
265
265
while (srclen && *dst && *src == *dst)
266
266
{
267
- --srclen; ++dst; ++src;
267
+ --srclen; ++dst; ++src;
268
268
}
269
269
return srclen == 0 && *dst == 0 ;
270
270
}
@@ -4780,6 +4780,9 @@ PUGI_IMPL_NS_BEGIN
4780
4780
// if convert_buffer below throws bad_alloc, we still need to deallocate contents if we own it
4781
4781
auto_deleter<void > contents_guard (own ? contents : NULL , xml_memory::deallocate);
4782
4782
4783
+ // early-out for empty documents to avoid buffer allocation overhead
4784
+ if (size == 0 ) return make_parse_result ((options & parse_fragment) ? status_ok : status_no_document_element);
4785
+
4783
4786
// get private buffer
4784
4787
char_t * buffer = NULL ;
4785
4788
size_t length = 0 ;
Original file line number Diff line number Diff line change @@ -473,6 +473,17 @@ TEST(document_load_string)
473
473
CHECK_NODE (doc, STR (" <node/>" ));
474
474
}
475
475
476
+ TEST (document_load_string_empty)
477
+ {
478
+ xml_document doc;
479
+
480
+ CHECK (doc.load_string (STR (" " )).status == status_no_document_element);
481
+ CHECK (!doc.first_child ());
482
+
483
+ CHECK (doc.load_string (STR (" " ), parse_fragment));
484
+ CHECK (!doc.first_child ());
485
+ }
486
+
476
487
TEST (document_load_file)
477
488
{
478
489
xml_document doc;
@@ -864,6 +875,19 @@ TEST(document_load_buffer_inplace_own)
864
875
CHECK_NODE (doc, STR (" <node/>" ));
865
876
}
866
877
878
+ TEST (document_load_buffer_inplace_own_empty)
879
+ {
880
+ allocation_function alloc = get_memory_allocation_function ();
881
+
882
+ void * text1 = alloc (1 );
883
+ void * text2 = alloc (1 );
884
+ CHECK (text1 && text2);
885
+
886
+ xml_document doc;
887
+ CHECK (doc.load_buffer_inplace_own (text1, 0 , parse_fragment));
888
+ CHECK (doc.load_buffer_inplace_own (text2, 0 ).status == status_no_document_element);
889
+ }
890
+
867
891
TEST (document_parse_result_bool)
868
892
{
869
893
xml_parse_result result;
You can’t perform that action at this time.
0 commit comments