Switch from using strncpy to strncpy_s. (#1809)

This commit is contained in:
Andreas Süßenbach 2024-02-19 16:06:28 +01:00 committed by GitHub
parent 38e3e8f800
commit 4c130b9051
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10722,16 +10722,13 @@ std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pair<st
assert( mit->arraySizes.size() == 1 ); assert( mit->arraySizes.size() == 1 );
static const std::string copyOpsTemplate = R"( static const std::string copyOpsTemplate = R"(
VULKAN_HPP_ASSERT( ${memberName}_.size() < ${arraySize} ); VULKAN_HPP_ASSERT( ${memberName}_.size() < ${arraySize} );
${copyOp}( ${memberName}, ${memberName}_.data(), ${arraySizeExpression} );)"; ${copyOp}( ${memberName}, ${memberSize}, ${memberName}_.data(), ${memberName}_.size() );)";
std::string arraySizeExpression = ( mit->lenExpressions[0] == "null-terminated" )
? ( "std::min<size_t>( " + mit->name + "_.size(), " + mit->arraySizes[0] + " )" )
: ( mit->lenExpressions[0] + " * sizeof( " + argumentType + " )" );
copyOps += replaceWithMap( copyOpsTemplate, copyOps += replaceWithMap( copyOpsTemplate,
{ { "arraySize", mit->arraySizes[0] }, { { "arraySize", mit->arraySizes[0] },
{ "arraySizeExpression", arraySizeExpression }, { "copyOp", mit->lenExpressions[0] == "null-terminated" ? "strncpy_s" : "memcpy_s" },
{ "copyOp", mit->lenExpressions[0] == "null-terminated" ? "strncpy" : "memcpy" }, { "memberName", mit->name },
{ "memberName", mit->name } } ); { "memberSize", mit->arraySizes[0] } } );
} }
} }
else else
@ -11450,7 +11447,7 @@ std::string VulkanHppGenerator::generateStructSetter( std::string const & struct
${structureName} & set${ArrayName}( std::string const & ${arrayName}_ ) VULKAN_HPP_NOEXCEPT ${structureName} & set${ArrayName}( std::string const & ${arrayName}_ ) VULKAN_HPP_NOEXCEPT
{ {
VULKAN_HPP_ASSERT( ${arrayName}_.size() < ${arraySize} ); VULKAN_HPP_ASSERT( ${arrayName}_.size() < ${arraySize} );
strncpy( ${arrayName}, ${arrayName}_.data(), std::min<size_t>( ${arrayName}_.size(), ${arraySize} ) ); strncpy_s( ${arrayName}, ${arraySize}, ${arrayName}_.data(), ${arrayName}_.size() );
return *this; return *this;
} }
#endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/