Skip to content

Modeling - Fix array indexing bug in IntAna_IntQuadQuad::NextCurve method#703

Merged
dpasukhi merged 4 commits intoOpen-Cascade-SAS:IRfrom
dpasukhi:int_ana_qq_access
Sep 6, 2025
Merged

Modeling - Fix array indexing bug in IntAna_IntQuadQuad::NextCurve method#703
dpasukhi merged 4 commits intoOpen-Cascade-SAS:IRfrom
dpasukhi:int_ana_qq_access

Conversation

@dpasukhi
Copy link
Copy Markdown
Member

@dpasukhi dpasukhi commented Sep 6, 2025

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

…ethod

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
@dpasukhi dpasukhi added this to the Release 7.9.3 milestone Sep 6, 2025
@dpasukhi dpasukhi requested a review from Copilot September 6, 2025 10:13
@dpasukhi dpasukhi self-assigned this Sep 6, 2025
@dpasukhi dpasukhi added 2. Bug Something isn't working 1. Modeling Boolean operations, offsets, primitives, any conversion, brep builders and etc... labels Sep 6, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a critical array indexing bug in the IntAna_IntQuadQuad::NextCurve method where inconsistent indexing between 1-indexed API parameters and 0-indexed array access could cause memory safety issues and incorrect results.

Key changes:

  • Corrected the indexing inconsistency in NextCurve method by using I-1 for both condition check and return value
  • Added comprehensive test coverage for the NextCurve functionality with edge cases and performance validation
  • Simplified the conditional logic while maintaining the same behavior

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/ModelingData/TKGeomBase/IntAna/IntAna_IntQuadQuad.cxx Fixed array indexing bug by using consistent I-1 indexing and simplified conditional logic
src/ModelingData/TKGeomBase/GTests/IntAna_IntQuadQuad_Test.cxx Added comprehensive test suite covering NextCurve functionality, boundary conditions, and performance
src/ModelingData/TKGeomBase/GTests/FILES.cmake Updated build configuration to include the new test file

cylinder1 = gp_Cylinder(axis, 3.0);

// Create cone with semi-angle 30 degrees
cone1 = gp_Cone(axis, M_PI / 6, 2.0);
Copy link

Copilot AI Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Standard_Real instead of double for floating-point values. According to OCCT conventions, geometric calculations should use Standard_Real type.

Copilot generated this review using guidance from repository custom instructions.
for (Standard_Integer i = 1; i <= intersector.NbCurve(); i++)
{
const IntAna_Curve& aCurve = intersector.Curve(i);
EXPECT_TRUE(aCurve.IsOpen() || aCurve.IsConstant() || !aCurve.IsOpen());
Copy link

Copilot AI Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion is always true due to the logical structure A || B || !A. The condition aCurve.IsOpen() || !aCurve.IsOpen() will always evaluate to true regardless of the IsConstant() result, making this test meaningless.

Suggested change
EXPECT_TRUE(aCurve.IsOpen() || aCurve.IsConstant() || !aCurve.IsOpen());
EXPECT_TRUE(aCurve.IsOpen() || aCurve.IsConstant());

Copilot uses AI. Check for mistakes.
Comment on lines +144 to +145
gp_Sphere sphere1(axis1, 2.0);
gp_Sphere sphere2(axis2, 2.0);
Copy link

Copilot AI Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Standard_Real instead of double literals. These should be 2.0 should be written as Standard_Real(2.0) or defined as Standard_Real variables to follow OCCT type conventions.

Copilot generated this review using guidance from repository custom instructions.
IntAna_Quadric aSphere2Quad(sphere2);

IntAna_IntQuadQuad anIntersector;
anIntersector.Perform(gp_Cylinder(axis1, 2.0), aSphere2Quad, 1e-7);
Copy link

Copilot AI Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Standard_Real for tolerance value. The literal 1e-7 should be Standard_Real(1e-7) to follow OCCT type conventions.

Copilot generated this review using guidance from repository custom instructions.
@dpasukhi dpasukhi merged commit 80ce783 into Open-Cascade-SAS:IR Sep 6, 2025
23 checks passed
@dpasukhi dpasukhi deleted the int_ana_qq_access branch September 6, 2025 12:36
@github-project-automation github-project-automation bot moved this from Todo to Done in Maintenance Sep 6, 2025
@dpasukhi dpasukhi modified the milestones: Release 7.9.3, Release 7.9.2 Sep 6, 2025
dpasukhi added a commit that referenced this pull request Sep 6, 2025
…thod (#703)

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
dpasukhi added a commit that referenced this pull request Sep 6, 2025
…thod (#703)

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1. Modeling Boolean operations, offsets, primitives, any conversion, brep builders and etc... 2. Bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants