mirror of
https://github.com/zeux/pugixml.git
synced 2025-01-03 01:55:25 +08:00
Fix Clang 3.7 compatibility
Apparently Clang 3.7 implements C++ DR 1748 that makes placement new with null pointer undefined behavior. Which renders all C++ programs that rely on this invalid. Which includes pugixml. This is not very likely to happen in the wild because the allocations that are subject to this in pugixml are relatively small, but tests break because of this. Fix the issue by adding null pointer checks (that are completely redundant in all current compilers except Clang 3.7 but it's not like there is another option).
This commit is contained in:
parent
97afc16ef2
commit
d04df2a48b
@ -1157,6 +1157,7 @@ PUGI__NS_BEGIN
|
||||
{
|
||||
xml_memory_page* page;
|
||||
void* memory = alloc.allocate_object(sizeof(xml_attribute_struct), page);
|
||||
if (!memory) return 0;
|
||||
|
||||
return new (memory) xml_attribute_struct(page);
|
||||
}
|
||||
@ -1165,6 +1166,7 @@ PUGI__NS_BEGIN
|
||||
{
|
||||
xml_memory_page* page;
|
||||
void* memory = alloc.allocate_object(sizeof(xml_node_struct), page);
|
||||
if (!memory) return 0;
|
||||
|
||||
return new (memory) xml_node_struct(page, type);
|
||||
}
|
||||
@ -4714,6 +4716,7 @@ PUGI__NS_BEGIN
|
||||
static xml_stream_chunk* create()
|
||||
{
|
||||
void* memory = xml_memory::allocate(sizeof(xml_stream_chunk));
|
||||
if (!memory) return 0;
|
||||
|
||||
return new (memory) xml_stream_chunk();
|
||||
}
|
||||
@ -11606,6 +11609,7 @@ PUGI__NS_BEGIN
|
||||
static xpath_query_impl* create()
|
||||
{
|
||||
void* memory = xml_memory::allocate(sizeof(xpath_query_impl));
|
||||
if (!memory) return 0;
|
||||
|
||||
return new (memory) xpath_query_impl();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user