Browse Source

FIX: try to undefined behaviour by static_cast.

Kim Kulling 3 years ago
parent
commit
f59dd695c8
1 changed files with 7 additions and 5 deletions
  1. 7 5
      test/unit/utVertexTriangleAdjacency.cpp

+ 7 - 5
test/unit/utVertexTriangleAdjacency.cpp

@@ -53,6 +53,11 @@ protected:
     void checkMesh(const aiMesh &mesh);
     void checkMesh(const aiMesh &mesh);
 };
 };
 
 
+// ------------------------------------------------------------------------------------------------
+static unsigned int foo() {
+    return static_cast<unsigned int>(((float)rand() / static_cast<float>(RAND_MAX)) * 499);
+}
+
 // ------------------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------------------
 TEST_F(VTAdjacencyTest, largeRandomDataSet) {
 TEST_F(VTAdjacencyTest, largeRandomDataSet) {
     // build a test mesh with randomized input data
     // build a test mesh with randomized input data
@@ -72,11 +77,8 @@ TEST_F(VTAdjacencyTest, largeRandomDataSet) {
         if (499 == iCurrent) iCurrent = 0;
         if (499 == iCurrent) iCurrent = 0;
         face.mIndices[0] = iCurrent++;
         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);
     checkMesh(mesh);