]> OCCT Git - occt.git/commitdiff
Modeling - Fix array indexing bug in IntAna_IntQuadQuad::NextCurve method (#703)
authorPasukhin Dmitry <dpasukhi@opencascade.com>
Sat, 6 Sep 2025 12:36:48 +0000 (13:36 +0100)
committerdpasukhi <dpasukhi@opencascade.com>
Sat, 6 Sep 2025 20:18:29 +0000 (21:18 +0100)
Fixed a critical indexing bug in IntAna_IntQuadQuad::NextCurve where the
  method incorrectly used nextcurve[I] instead of nextcurve[I-1] for
  determining the theOpposite parameter.
This mismatch between 1-indexed API
  parameters and 0-indexed array access could lead to out-of-bounds memory
  access and incorrect curve connectivity determination.

Changes:
  - Fix IntAna_IntQuadQuad::NextCurve to use consistent I-1 indexing for both
   condition check and return value
  - Add comprehensive GTests covering NextCurve functionality, edge cases,
  and performance
  - Ensure proper error handling for invalid curve indices

src/IntAna/IntAna_IntQuadQuad.cxx

index 43d912843389cec8ce153cf2088529ae3498604a..9bade3f616719f702aae3f3b77c17bb1ecaf1b68 100644 (file)
@@ -1576,16 +1576,8 @@ Standard_Integer IntAna_IntQuadQuad::NextCurve(const Standard_Integer I,
 {
   if (HasNextCurve(I))
   {
-    if (nextcurve[I] > 0)
-    {
-      theOpposite = Standard_False;
-      return (nextcurve[I - 1]);
-    }
-    else
-    {
-      theOpposite = Standard_True;
-      return (-nextcurve[I - 1]);
-    }
+    theOpposite = nextcurve[I - 1] < 0;
+    return Abs(nextcurve[I - 1]);
   }
   else
   {