From 23e2d64d6ffd035773678e16a5b0db892e50c6b2 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Mon, 13 May 2024 06:52:10 +0900 Subject: [PATCH] Fix potential multiplication overflow reported by Code scanning. --- src/tydra/render-data.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/tydra/render-data.cc b/src/tydra/render-data.cc index c4df3f75..167c5670 100644 --- a/src/tydra/render-data.cc +++ b/src/tydra/render-data.cc @@ -2695,8 +2695,8 @@ bool RenderSceneConverter::BuildVertexIndicesImpl(RenderMesh &mesh) { "Internal error. Invalid elementSize in mesh.joint_and_weights."); } uint32_t elementSize = uint32_t(mesh.joint_and_weights.elementSize); - std::vector tmp_indices(numPoints * elementSize); - std::vector tmp_weights(numPoints * elementSize); + std::vector tmp_indices(size_t(numPoints) * size_t(elementSize)); + std::vector tmp_weights(size_t(numPoints) * size_t(elementSize)); for (size_t i = 0; i < out_point_indices.size(); i++) { if ((elementSize * out_point_indices[i]) >= mesh.joint_and_weights.jointIndices.size()) { @@ -2704,9 +2704,9 @@ bool RenderSceneConverter::BuildVertexIndicesImpl(RenderMesh &mesh) { "Internal error. point index exceeds jointIndices.size."); } for (size_t k = 0; k < elementSize; k++) { - tmp_indices[elementSize * out_indices[i] + k] = + tmp_indices[size_t(elementSize) * size_t(out_indices[i]) + k] = mesh.joint_and_weights - .jointIndices[elementSize * out_point_indices[i] + k]; + .jointIndices[size_t(elementSize) * size_t(out_point_indices[i]) + k]; } if ((elementSize * out_point_indices[i]) >= @@ -2716,9 +2716,9 @@ bool RenderSceneConverter::BuildVertexIndicesImpl(RenderMesh &mesh) { } for (size_t k = 0; k < elementSize; k++) { - tmp_weights[elementSize * out_indices[i] + k] = + tmp_weights[size_t(elementSize) * size_t(out_indices[i]) + k] = mesh.joint_and_weights - .jointWeights[elementSize * out_point_indices[i] + k]; + .jointWeights[size_t(elementSize) * size_t(out_point_indices[i]) + k]; } } mesh.joint_and_weights.jointIndices.swap(tmp_indices);