[BUG] Suspect boolean operators in C++ sources

Compiler warnings suggest that there may be problems with those 3 files (OCT 6.5.1):
ros/src/BRepOffset/BRepOffset_Inter2d.cxx
ros/src/TNaming/TNaming_Localizer.cxx
ros/src/TopOpeBRepTool/TopOpeBRepTool_makeTransition.cxx

Patches below show how operators are interpreted by compiler, these are not suggested fixes.

diff --git a/src/BRepOffset/BRepOffset_Inter2d.cxx b/src/BRepOffset/BRepOffset_Inter2d.cxx
index b18d3aa..0ead70b 100644
--- a/src/BRepOffset/BRepOffset_Inter2d.cxx
+++ b/src/BRepOffset/BRepOffset_Inter2d.cxx
@@ -1277,8 +1277,8 @@ static void ExtentEdge(const TopoDS_Edge& E,TopoDS_Edge& NE, const Standard_Real
Standard_Real FirstPar = C3d->FirstParameter();
Standard_Real LastPar = C3d->LastParameter();

- if (C3d->IsKind(STANDARD_TYPE(Geom_BoundedCurve)) &&
- FirstPar > anEf - a2Offset || LastPar + if ((C3d->IsKind(STANDARD_TYPE(Geom_BoundedCurve)) &&
+ FirstPar > anEf - a2Offset) || LastPar {
Handle(Geom_TrimmedCurve) aTrCurve =
new Geom_TrimmedCurve(C3d, FirstPar, LastPar);

Maybe one wanted to write instead:
if (C3d->IsKind(STANDARD_TYPE(Geom_BoundedCurve) &&
(FirstPar > anEf - a2Offset || LastPar

diff --git a/src/TNaming/TNaming_Localizer.cxx b/src/TNaming/TNaming_Localizer.cxx
index 640628b..6864dd6 100644
--- a/src/TNaming/TNaming_Localizer.cxx
+++ b/src/TNaming/TNaming_Localizer.cxx
@@ -244,7 +244,7 @@ const TopTools_IndexedDataMapOfShapeListOfShape& TNaming_Localizer::Ancestors
if (TS == TopAbs_EDGE) TA = TopAbs_FACE;
if (TS == TopAbs_VERTEX) TA = TopAbs_EDGE;
if (TS == TopAbs_FACE) TA = TopAbs_SOLID;// 25.09.2009 - szy
- if (TS == TopAbs_EDGE || TS == TopAbs_VERTEX || TS == TopAbs_FACE && TA >= In.ShapeType()) {
+ if (TS == TopAbs_EDGE || TS == TopAbs_VERTEX || (TS == TopAbs_FACE && TA >= In.ShapeType())) {
TopExp::MapShapesAndAncestors(In, TS, TA, myAncestors.First());
}
else {

Maybe this line is expected instead:
if ((TS == TopAbs_EDGE || TS == TopAbs_VERTEX || TS == TopAbs_FACE) && TA >= In.ShapeType()) {

diff --git a/src/TopOpeBRepTool/TopOpeBRepTool_makeTransition.cxx b/src/TopOpeBRepTool/TopOpeBRepTool_makeTransition.cxx
index 5188c9a..b011f8d 100644
--- a/src/TopOpeBRepTool/TopOpeBRepTool_makeTransition.cxx
+++ b/src/TopOpeBRepTool/TopOpeBRepTool_makeTransition.cxx
@@ -254,14 +254,14 @@ static Standard_Boolean FUN_mkT2dquad(const TopoDS_Edge& e1,const Standard_Real
// = sta = state of point on e1 after pt / e2

gp_Dir tga1,tga2;
- Standard_Boolean mk1 = isINifh1 || isON2ifss || isIN2ifss;
+ Standard_Boolean mk1 = Standard_True;
if (mk1) {
Standard_Integer st1 = 0; gp_Dir tgnear1;
Standard_Boolean ok = FUN_tg(e1,par1,f1,l1,factor,tgnear1,st1);
if (!ok) return Standard_False;
tga1 = (st1 == AFTER) ? tgnear1 : tgnear1.Reversed();
}
- Standard_Boolean mk2 = isINifh2 || isON2ifss || isOU2ifss;
+ Standard_Boolean mk2 = Standard_True;
if (mk2) {
Standard_Real f2,l2; FUN_tool_bounds(e2,f2,l2);
Standard_Integer st2 = 0; gp_Dir tgnear2;

These two statements should probably be rewritten as in FUN_mkT3dquad:
Standard_Boolean mke = (mkt==isINifh1) || (mkt==isON2ifss) || (mkt==isIN2ifss);

Cauchy Ding's picture

My occ source code is 6.3. I agree with you about the first item.I think it's a bug. About the second item, 6.3 and 6.5 have different definition of TNaming_Localizer::Ancestors. No idea about it. No idea about the third item also.

Ding

Forum supervisor's picture

Hello, Denis,
we have tried to investigate these issues and here's an intermediate result.

1. For case 1 (file BRepOffset_Inter2d.cxx) I have registered a bug with ID=OCC22688 in our Bugtracker, this issue really needs to be corrected.

2. For case 2 (TNaming_Localizer.cxx) please, provide additional information:
- OS version
- Compiler version
- any other information that will help to reproduce the problem

3. For case 3 (TopOpeBRepTool_makeTransition.cxx), the error is not evident. So here we also need additional information to distinguish the error (it may be, for example, a set of data in .brep format and a script in .tcl format with DRAW commands illustrating the bug that is presumably caused by this error).
Thank you for your feedback and best regards.

Denis Barbier's picture

Hello Forum Supervisor,

In OCE we want to get rid of all compiler warnings. There are currently too many warnings, and real bugs are hidden by the huge pile of warnings.
When fixing sources to eliminate those compiler warnings, we found the reported problems. So I have no test case to provide, these lines look wrong, but we are unsure.