Correct operator=() by using offsetof instead of sizeof to determine size of memory to copy. (#437)

This commit is contained in:
Andreas Süßenbach 2019-11-19 17:44:16 +01:00 committed by Markus Tavenrath
parent 2bd8e403e8
commit d2a116b57f
2 changed files with 387 additions and 383 deletions

View File

@ -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 // 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")) 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")); 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"; static const std::string stringTemplate = R"(
structConstructor += prefix + "}\n"; ${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; return structConstructor;

File diff suppressed because it is too large Load Diff