]> OCCT Git - occt-copy.git/commitdiff
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)
committerkgv <kgv@opencascade.com>
Mon, 4 Dec 2017 18:17:40 +0000 (21:17 +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 6478f1797c914e3f9868c1ce8c7ac5296f6e5b56..98ed552d77ddc7c10ced38de5b611e73fad3bf77 100644 (file)
@@ -331,10 +331,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);
   }
@@ -343,7 +344,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 c90e5baf490a5398ac577ea8627a87eee299378a..ea72f3fe0f0a11afe23870ecb1f362125f87984f 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);