Archived issue #0030565

Coding - Approx_SweepApproximation call on null pointer

CommunityOCCT:Codingclosed4 public notes

Search issues

Description

I compiled OCCT with the -fsanitize=undefined flag and got the following errors:

src/Approx/Approx_SweepApproximation.cxx:179:31: runtime error: member call on null pointer of type 'struct TColgp_HArray1OfVec2d'
src/Approx/Approx_SweepApproximation.cxx:179:31: runtime error: member access within null pointer of type 'struct TColgp_HArray1OfVec2d'

This is a problem when Num2DSS==0 the arrays:

 if (Num2DSS>0) {
   myPoles2d = new (TColgp_HArray1OfPnt2d)(1, Num2DSS);
   myDPoles2d = new (TColgp_HArray1OfVec2d)(1, Num2DSS);
   myD2Poles2d = new (TColgp_HArray1OfVec2d)(1, Num2DSS);
   COnSurfErr = new (TColStd_HArray1OfReal)(1, Num2DSS);
 }

which are then used on line 179. This fix avoids the null pointer:

 myPoles2d = new (TColgp_HArray1OfPnt2d)(1, std::max(Num2DSS,1));
 myDPoles2d = new (TColgp_HArray1OfVec2d)(1, std::max(Num2DSS,1));
 myD2Poles2d = new (TColgp_HArray1OfVec2d)(1, std::max(Num2DSS,1));
 COnSurfErr = new (TColStd_HArray1OfReal)(1, std::max(Num2DSS,1));

but may not be the right solution.

Steps to reproduce

Compile OCCT with a g++ newer than 4.9 with the -fsanitize=undefined compiler flag and run the test suite.

Public activity

4 archived notes

Participants are labeled by their role within this record.

01Commenter 4
Should be fixed by #0030582.
Please check, if possible.
02Author
This will be tricky for me to check as there are a large number of changes. I could try to put together an example for you if you would like?
03Author
As best as I can tell it looks like the fix in 0030582 should resolve this problem.
04Commenter 4
Dear Commenter 1,

please switch this bug to VERIFIED (fixed in scope of #0030582).

Related records