0029170: GCC 7.1 warnings -Wstrict-aliasing in Graphic3d_ArrayOfPrimitives.hxx
authorabv <abv@opencascade.com>
Sat, 30 Sep 2017 18:35:05 +0000 (21:35 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 6 Oct 2017 07:27:59 +0000 (10:27 +0300)
Methods Graphic3d_ArrayOfPrimitives::SetVertexColor() accepting color as three double rgb values and Graphic3d_Vec4ub object are refactored to avoid using reinterpret_cast between pointers to complex types.

Similar correction is made in ViewerTest_ObjectCommands.cxx (static function VDrawSphere).

src/Graphic3d/Graphic3d_ArrayOfPrimitives.hxx
src/ViewerTest/ViewerTest_ObjectCommands.cxx

index 9d78df5..fb4c72a 100644 (file)
@@ -344,10 +344,11 @@ public:
 
     if (myVCol != 0)
     {
-      Graphic3d_Vec4ub aColor (Standard_Byte(theR * 255.0),
-                               Standard_Byte(theG * 255.0),
-                               Standard_Byte(theB * 255.0), 255);
-      SetVertexColor (theIndex, *reinterpret_cast<Standard_Integer*>(&aColor));
+      Graphic3d_Vec4ub *aColorPtr = 
+        reinterpret_cast<Graphic3d_Vec4ub* >(myAttribs->changeValue (theIndex - 1) + size_t(myVCol));
+      aColorPtr->SetValues (Standard_Byte(theR * 255.0),
+                            Standard_Byte(theG * 255.0),
+                            Standard_Byte(theB * 255.0), 255);
     }
     myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
   }
@@ -356,7 +357,23 @@ public:
   void SetVertexColor (const Standard_Integer  theIndex,
                        const Graphic3d_Vec4ub& theColor)
   {
-    SetVertexColor (theIndex, *reinterpret_cast<const Standard_Integer*> (&theColor));
+    if (myAttribs.IsNull())
+    {
+      return;
+    }
+    else if (theIndex < 1
+          || theIndex > myMaxVertexs)
+    {
+      throw Standard_OutOfRange ("BAD VERTEX index");
+    }
+
+    if (myVCol != 0)
+    {
+      Graphic3d_Vec4ub *aColorPtr = 
+        reinterpret_cast<Graphic3d_Vec4ub* >(myAttribs->changeValue (theIndex - 1) + size_t(myVCol));
+      (*aColorPtr) = theColor;
+    }
+    myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
   }
 
   //! Change the vertex color of rank theIndex> in the array.
index 75950fd..ec3565c 100644 (file)
@@ -2960,7 +2960,7 @@ static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const c
   Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
   for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
   {
-    aColorArray->SetValue (aNodeId, *reinterpret_cast<const Standard_Integer*> (&aColor));
+    aColorArray->SetValue (aNodeId, *reinterpret_cast<const Standard_Integer*> (aColor.GetData()));
   }
   aShape->SetColors (aColorArray);