Skip to content

Commit

Permalink
Fix potential multiplication overflow reported by Code scanning.
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed May 12, 2024
1 parent d22bf14 commit 23e2d64
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/tydra/render-data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2695,18 +2695,18 @@ 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<int> tmp_indices(numPoints * elementSize);
std::vector<float> tmp_weights(numPoints * elementSize);
std::vector<int> tmp_indices(size_t(numPoints) * size_t(elementSize));
std::vector<float> 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()) {
PUSH_ERROR_AND_RETURN(
"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]) >=
Expand All @@ -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);
Expand Down

0 comments on commit 23e2d64

Please sign in to comment.