diff options
author | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2014-11-02 09:30:56 +0100 |
---|---|---|
committer | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2014-11-02 09:30:56 +0100 |
commit | e9948b4b05ca23cb95a6ca75ce4ee840e1fbda9b (patch) | |
tree | 798c9638505748dd1adc6313e56a0f80120c243a /src/pugixml.cpp | |
parent | f68a320a0203279db2e8692cc9e21f71551454e4 (diff) |
Fix undefined behavior while calling memcpy
Calling memcpy(x, 0, 0) is technically undefined (although it should usually
be a no-op).
Diffstat (limited to 'src/pugixml.cpp')
-rw-r--r-- | src/pugixml.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
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<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; |