diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 540e4c0..1906856 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -2531,8 +2531,9 @@ void VulkanHppGenerator::appendStructCompareOperators(std::string & str, std::pa // two structs are compared by comparing each of the elements std::string compareMembers; std::string intro = ""; - for (auto const& member : structData.second.members) + for (size_t i = 0; i < structData.second.members.size(); i++) { + MemberData const& member = structData.second.members[i]; compareMembers += intro; if (member.arraySize.empty()) { @@ -2540,7 +2541,13 @@ void VulkanHppGenerator::appendStructCompareOperators(std::string & str, std::pa } else { - compareMembers += "( memcmp( " + member.name + ", rhs." + member.name + ", " + member.arraySize + " * sizeof( " + member.type.compose() + " ) ) == 0 )"; + std::string arraySize = member.arraySize; + if ((0 < i) && ((stripPostfix(member.name, "s") + "Count") == structData.second.members[i - 1].name)) + { + assert(structData.second.members[i - 1].type.type == "uint32_t"); // make sure, it's an unsigned type, so we don't need to clamp here + arraySize = "std::min<" + structData.second.members[i-1].type.type + ">( " + arraySize + ", " + structData.second.members[i - 1].name + " )"; + } + compareMembers += "( memcmp( " + member.name + ", rhs." + member.name + ", " + arraySize + " * sizeof( " + member.type.compose() + " ) ) == 0 )"; } intro = "\n && "; } diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index a0196f2..c65f807 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -44202,7 +44202,7 @@ namespace VULKAN_HPP_NAMESPACE return ( sType == rhs.sType ) && ( pNext == rhs.pNext ) && ( physicalDeviceCount == rhs.physicalDeviceCount ) - && ( memcmp( physicalDevices, rhs.physicalDevices, VK_MAX_DEVICE_GROUP_SIZE * sizeof( VULKAN_HPP_NAMESPACE::PhysicalDevice ) ) == 0 ) + && ( memcmp( physicalDevices, rhs.physicalDevices, std::min( VK_MAX_DEVICE_GROUP_SIZE, physicalDeviceCount ) * sizeof( VULKAN_HPP_NAMESPACE::PhysicalDevice ) ) == 0 ) && ( subsetAllocation == rhs.subsetAllocation ); } @@ -45757,9 +45757,9 @@ namespace VULKAN_HPP_NAMESPACE bool operator==( PhysicalDeviceMemoryProperties const& rhs ) const VULKAN_HPP_NOEXCEPT { return ( memoryTypeCount == rhs.memoryTypeCount ) - && ( memcmp( memoryTypes, rhs.memoryTypes, VK_MAX_MEMORY_TYPES * sizeof( VULKAN_HPP_NAMESPACE::MemoryType ) ) == 0 ) + && ( memcmp( memoryTypes, rhs.memoryTypes, std::min( VK_MAX_MEMORY_TYPES, memoryTypeCount ) * sizeof( VULKAN_HPP_NAMESPACE::MemoryType ) ) == 0 ) && ( memoryHeapCount == rhs.memoryHeapCount ) - && ( memcmp( memoryHeaps, rhs.memoryHeaps, VK_MAX_MEMORY_HEAPS * sizeof( VULKAN_HPP_NAMESPACE::MemoryHeap ) ) == 0 ); + && ( memcmp( memoryHeaps, rhs.memoryHeaps, std::min( VK_MAX_MEMORY_HEAPS, memoryHeapCount ) * sizeof( VULKAN_HPP_NAMESPACE::MemoryHeap ) ) == 0 ); } bool operator!=( PhysicalDeviceMemoryProperties const& rhs ) const VULKAN_HPP_NOEXCEPT