mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Correct operator=() by using offsetof instead of sizeof to determine size of memory to copy. (#437)
This commit is contained in:
parent
2bd8e403e8
commit
d2a116b57f
@ -2659,12 +2659,16 @@ std::string VulkanHppGenerator::appendStructConstructor(std::pair<std::string, S
|
||||
// we need a copy constructor if there is constant sType in this struct
|
||||
if ((nonConstSTypeStructs.find(structData.first) == nonConstSTypeStructs.end()) && !structData.second.members.empty() && (structData.second.members.front().name == "sType"))
|
||||
{
|
||||
structConstructor += "\n" + prefix + "vk::" + stripPrefix(structData.first, "Vk") + " & operator=( vk::" + stripPrefix(structData.first, "Vk") + " const & rhs ) VULKAN_HPP_NOEXCEPT\n";
|
||||
structConstructor += prefix + "{\n";
|
||||
assert((2 <= structData.second.members.size()) && (structData.second.members[1].name == "pNext"));
|
||||
structConstructor += prefix + " memcpy( &pNext, &rhs.pNext, sizeof( vk::" + stripPrefix(structData.first, "Vk") + " ) - sizeof( vk::StructureType ) );\n";
|
||||
structConstructor += prefix + " return *this;\n";
|
||||
structConstructor += prefix + "}\n";
|
||||
|
||||
static const std::string stringTemplate = R"(
|
||||
${prefix}vk::${structName} & operator=( vk::${structName} const & rhs ) VULKAN_HPP_NOEXCEPT
|
||||
${prefix}{
|
||||
${prefix} memcpy( &pNext, &rhs.pNext, sizeof( vk::${structName} ) - offsetof( ${structName}, pNext ) );
|
||||
${prefix} return *this;
|
||||
${prefix}}
|
||||
)";
|
||||
structConstructor += replaceWithMap(stringTemplate, { {"prefix", prefix }, { "structName", stripPrefix(structData.first, "Vk") } });
|
||||
}
|
||||
|
||||
return structConstructor;
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user