From e9948b4b05ca23cb95a6ca75ce4ee840e1fbda9b Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sun, 2 Nov 2014 09:30:56 +0100 Subject: Fix undefined behavior while calling memcpy Calling memcpy(x, 0, 0) is technically undefined (although it should usually be a no-op). --- src/pugixml.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 4b1d5ab..59e8f79 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -1352,7 +1352,11 @@ PUGI__NS_BEGIN char_t* buffer = static_cast(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; -- cgit v1.2.3