mirror of
https://github.com/zeux/pugixml.git
synced 2025-01-14 18:07:59 +08:00
Fix undefined behavior while calling memcpy
Calling memcpy(x, 0, 0) is technically undefined (although it should usually be a no-op).
This commit is contained in:
parent
f68a320a02
commit
e9948b4b05
@ -1352,7 +1352,11 @@ PUGI__NS_BEGIN
|
||||
char_t* buffer = static_cast<char_t*>(xml_memory::allocate((length + 1) * sizeof(char_t)));
|
||||
if (!buffer) return false;
|
||||
|
||||
memcpy(buffer, contents, length * sizeof(char_t));
|
||||
if (contents)
|
||||
memcpy(buffer, contents, length * sizeof(char_t));
|
||||
else
|
||||
assert(length == 0);
|
||||
|
||||
buffer[length] = 0;
|
||||
|
||||
out_buffer = buffer;
|
||||
|
@ -1091,6 +1091,19 @@ TEST_XML(dom_node_append_buffer_fragment, "<node />")
|
||||
CHECK_NODE(doc, STR("<node>1234</node>"));
|
||||
}
|
||||
|
||||
TEST_XML(dom_node_append_buffer_empty, "<node />")
|
||||
{
|
||||
xml_node node = doc.child(STR("node"));
|
||||
|
||||
CHECK(node.append_buffer("", 0).status == status_no_document_element);
|
||||
CHECK(node.append_buffer("", 0, parse_fragment).status == status_ok);
|
||||
|
||||
CHECK(node.append_buffer(0, 0).status == status_no_document_element);
|
||||
CHECK(node.append_buffer(0, 0, parse_fragment).status == status_ok);
|
||||
|
||||
CHECK_NODE(doc, STR("<node />"));
|
||||
}
|
||||
|
||||
TEST_XML(dom_node_prepend_move, "<node>foo<child/></node>")
|
||||
{
|
||||
xml_node child = doc.child(STR("node")).child(STR("child"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user