From f59dd695c8be0d6a79fa5039c4dbcbaa1257ff5c Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 18 Sep 2022 16:03:54 +0200 Subject: [PATCH] FIX: try to undefined behaviour by static_cast. --- test/unit/utVertexTriangleAdjacency.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/unit/utVertexTriangleAdjacency.cpp b/test/unit/utVertexTriangleAdjacency.cpp index bda6304e0..8c8d9db04 100644 --- a/test/unit/utVertexTriangleAdjacency.cpp +++ b/test/unit/utVertexTriangleAdjacency.cpp @@ -53,6 +53,11 @@ protected: void checkMesh(const aiMesh &mesh); }; +// ------------------------------------------------------------------------------------------------ +static unsigned int foo() { + return static_cast(((float)rand() / static_cast(RAND_MAX)) * 499); +} + // ------------------------------------------------------------------------------------------------ TEST_F(VTAdjacencyTest, largeRandomDataSet) { // build a test mesh with randomized input data @@ -72,11 +77,8 @@ TEST_F(VTAdjacencyTest, largeRandomDataSet) { if (499 == iCurrent) iCurrent = 0; face.mIndices[0] = iCurrent++; - while (face.mIndices[0] == (face.mIndices[1] = (unsigned int)(((float)rand() / RAND_MAX) * 499))) - ; - while (face.mIndices[0] == (face.mIndices[2] = (unsigned int)(((float)rand() / RAND_MAX) * 499)) || - face.mIndices[1] == face.mIndices[2]) - ; + while (face.mIndices[0] == (face.mIndices[1] = foo())); + while (face.mIndices[0] == (face.mIndices[2] = foo()) || face.mIndices[1] == face.mIndices[2]); } checkMesh(mesh);