0032041: Modeling Data - Access violation ExchangeUV in Geom_BezierSurface
authorkgv <kgv@opencascade.com>
Thu, 7 Jan 2021 20:10:27 +0000 (23:10 +0300)
committerbugmaster <bugmaster@opencascade.com>
Tue, 12 Jan 2021 10:30:35 +0000 (13:30 +0300)
Added missing NULL-checks to Geom_BezierSurface::ExchangeUV() and Geom_BSplineSurface::ExchangeUV().

src/Geom/Geom_BSplineSurface.cxx
src/Geom/Geom_BezierSurface.cxx
tests/bugs/moddata_3/bug32041 [new file with mode: 0644]

index 5316b0c385e7986362381838fc112094c5c5043d..7b5c9f5ef3e97d19d6b63c103b4003a70ee2234a 100644 (file)
@@ -300,48 +300,37 @@ void Geom_BSplineSurface::ExchangeUV ()
   Standard_Integer LR = poles->LowerRow();
   Standard_Integer UR = poles->UpperRow();
 
-  Handle(TColgp_HArray2OfPnt)   npoles   = 
-    new TColgp_HArray2OfPnt  (LC, UC, LR, UR);
-  Handle(TColStd_HArray2OfReal) nweights = 
-    new TColStd_HArray2OfReal (LC, UC, LR, UR);
+  Handle(TColgp_HArray2OfPnt) npoles = new TColgp_HArray2OfPnt (LC, UC, LR, UR);
+  Handle(TColStd_HArray2OfReal) nweights;
+  if (!weights.IsNull())
+  {
+    nweights = new TColStd_HArray2OfReal (LC, UC, LR, UR);
+  }
 
-  const TColgp_Array2OfPnt   & spoles   = poles->Array2();
-  const TColStd_Array2OfReal & sweights = weights->Array2();
+  const TColgp_Array2OfPnt& spoles = poles->Array2();
+  const TColStd_Array2OfReal* sweights = !weights.IsNull() ? &weights->Array2() : NULL;
   
-  TColgp_Array2OfPnt&   snpoles   = npoles->ChangeArray2();
-  TColStd_Array2OfReal& snweights = nweights->ChangeArray2();
-  
-  Standard_Integer i, j;
-  for (i = LC; i <= UC; i++) {
-    for (j = LR; j <= UR; j++) {
-      snpoles   (i,j) = spoles   (j,i);
-      snweights (i,j) = sweights (j,i);
+  TColgp_Array2OfPnt& snpoles = npoles->ChangeArray2();
+  TColStd_Array2OfReal* snweights = !nweights.IsNull() ? &nweights->ChangeArray2() : NULL;
+  for (Standard_Integer i = LC; i <= UC; i++)
+  {
+    for (Standard_Integer j = LR; j <= UR; j++)
+    {
+      snpoles (i, j) = spoles (j, i);
+      if (snweights != NULL)
+      {
+        snweights->ChangeValue (i, j) = sweights->Value (j, i);
+      }
     }
   }
-
   poles   = npoles;
   weights = nweights;
 
-  Standard_Boolean temp = urational;
-  urational = vrational;
-  vrational = temp;
-
-  temp = uperiodic;
-  uperiodic = vperiodic;
-  vperiodic = temp;
-
-  Standard_Integer tempdeg = udeg;
-  udeg = vdeg;
-  vdeg = tempdeg;
-  
-
-  Handle(TColStd_HArray1OfReal) tempknots = uknots;
-  uknots = vknots;
-  vknots = tempknots;
-
-  Handle(TColStd_HArray1OfInteger) tempmults = umults;
-  umults = vmults;
-  vmults = tempmults;
+  std::swap (urational, vrational);
+  std::swap (uperiodic, vperiodic);
+  std::swap (udeg,   vdeg);
+  std::swap (uknots, vknots);
+  std::swap (umults, vmults);
 
   UpdateUKnots();
   UpdateVKnots();
index 9e14f232a3ae973e60aabf11b4b5f59b406790b4..664fd90495ca83fe3dc174dfb6cd6e8ce18ae4d0 100644 (file)
@@ -505,31 +505,33 @@ void Geom_BezierSurface::ExchangeUV ()
   Standard_Integer LR = poles->LowerRow();
   Standard_Integer UR = poles->UpperRow();
 
-  Handle(TColgp_HArray2OfPnt) npoles = 
-    new TColgp_HArray2OfPnt (LC, UC, LR, UR);
-  Handle(TColStd_HArray2OfReal) nweights =
-    new TColStd_HArray2OfReal (LC, UC, LR, UR);
-
-  const TColgp_Array2OfPnt   & spoles   = poles->Array2();
-  const TColStd_Array2OfReal & sweights = weights->Array2();
-
-  TColgp_Array2OfPnt&   snpoles   = npoles->ChangeArray2();
-  TColStd_Array2OfReal& snweights = nweights->ChangeArray2();
-  Standard_Integer i, j;
-  for (i = LC; i <= UC; i++) {
-    for (j = LR; j <= UR; j++) {
-      snpoles   (i,j) = spoles   (j,i);
-      snweights (i,j) = sweights (j,i);
+  Handle(TColgp_HArray2OfPnt) npoles = new TColgp_HArray2OfPnt (LC, UC, LR, UR);
+  Handle(TColStd_HArray2OfReal) nweights;
+  if (!weights.IsNull())
+  {
+    nweights = new TColStd_HArray2OfReal (LC, UC, LR, UR);
+  }
+
+  const TColgp_Array2OfPnt& spoles = poles->Array2();
+  const TColStd_Array2OfReal* sweights = !weights.IsNull() ? &weights->Array2() : NULL;
+
+  TColgp_Array2OfPnt& snpoles = npoles->ChangeArray2();
+  TColStd_Array2OfReal* snweights = !nweights.IsNull() ? &nweights->ChangeArray2() : NULL;
+  for (Standard_Integer i = LC; i <= UC; i++)
+  {
+    for (Standard_Integer j = LR; j <= UR; j++)
+    {
+      snpoles (i, j) = spoles (j, i);
+      if (snweights != NULL)
+      {
+        snweights->ChangeValue (i, j) = sweights->Value (j, i);
+      }
     }
   }
-
   poles   = npoles;
   weights = nweights;
 
-  Standard_Boolean temp = urational;
-  urational = vrational;
-  vrational = temp;
+  std::swap (urational, vrational);
 }
 
 //=======================================================================
diff --git a/tests/bugs/moddata_3/bug32041 b/tests/bugs/moddata_3/bug32041
new file mode 100644 (file)
index 0000000..5d592ad
--- /dev/null
@@ -0,0 +1,12 @@
+puts "========="
+puts "0032041: Modeling Data - Access v i o l a t i o n ExchangeUV in Geom_BezierSurface"
+puts "========="
+puts ""
+
+pload MODELING
+beziersurf bs 4 4  0  0 0  4 0 0  8 0 0  12 0 0 0  4 0  4 4 1  8 4 0  12 4 0 0  8 0  4 8 0  8 8 -1  12 8 0 0 12 0 4 12 0 8 12 0 12 12 0
+smallview
+fit
+xwd ${imagedir}/${casename}_1.png
+exchuv bs
+xwd ${imagedir}/${casename}_2.png