Archived issue #0025720
Incorrect code of math classes can lead to unpredicted behavior of algorithms
Description
This bug has been detected during discussion in the following forum topic:
http://dev.opencascade.org/index.php?q=node/1048
The quote of the user barbier:
"scan-build is able to detect such problems, it reports similar problems in
math_Powell.cxx
math_NewtonMinimum.cxx
math_NewtonFunctionSetRoot.cxx
math_BissecNewton.cxx math_FRPR.cxx
math_FunctionSetRoot.cxx
math_FunctionSetRoot.cxx
math_BrentMinimum.cxx
It also complains about Delete being called by virtual destructors."
The matter is about the calling of virtual functions from the constructor. This must be avoided, in our case mainly by suppressing call to Perform method from the constructor.
Also, of course, it is needed to avoid calling virtual functions from destructors.
http://dev.opencascade.org/index.php?q=node/1048
The quote of the user barbier:
"scan-build is able to detect such problems, it reports similar problems in
math_Powell.cxx
math_NewtonMinimum.cxx
math_NewtonFunctionSetRoot.cxx
math_BissecNewton.cxx math_FRPR.cxx
math_FunctionSetRoot.cxx
math_FunctionSetRoot.cxx
math_BrentMinimum.cxx
It also complains about Delete being called by virtual destructors."
The matter is about the calling of virtual functions from the constructor. This must be avoided, in our case mainly by suppressing call to Perform method from the constructor.
Also, of course, it is needed to avoid calling virtual functions from destructors.
Steps to reproduce
not applicable
Public activity
20 archived notes
Participants are labeled by their role within this record.
Branch [archived branch] has been created by Participant.
[revision removed]
Detailed log of new commits:
Author: azn
Date: Thu Jan 22 15:19:05 2015 +0300
0025720: Incorrect code of math classes can lead to unpredicted behavior of algorithms
The inheritance interfaces were eliminated from the following classes:
math_BissecNewton
math_BrentMinimum.cdl
math_FRPR.cdl
math_FRPR.cxx
math_FunctionSetRoot
math_FunctionSetRoot
math_NewtonFunctionSetRoot
math_NewtonFunctionSetRoot
math_Powell
math_Powell
<-- these classes are no heirs
Fixed: math_NewtonMinimum class
[revision removed]
Detailed log of new commits:
Author: azn
Date: Thu Jan 22 15:19:05 2015 +0300
0025720: Incorrect code of math classes can lead to unpredicted behavior of algorithms
The inheritance interfaces were eliminated from the following classes:
math_BissecNewton
math_BrentMinimum.cdl
math_FRPR.cdl
math_FRPR.cxx
math_FunctionSetRoot
math_FunctionSetRoot
math_NewtonFunctionSetRoot
math_NewtonFunctionSetRoot
math_Powell
math_Powell
<-- these classes are no heirs
Fixed: math_NewtonMinimum class
Dear Mikhail,
Please review brunch CR25720
Please review brunch CR25720
IsSolutionReached is no more virtual, but comments say that it can be redefined.
If this method is called only from Perform and no more virtual, why not to make it inline?
src\math\math_NewtonMinimum.cdl:62 is a strange line, looks like a mistake. If you want to leave empty virtual destructor than define some non-virtual inline stub method and make alias virtual destructor calling this stub.
src\math\math_NewtonMinimum.cxx
The virtual method IsConverged is no more called. So, virtual mechanism is no more used. Why virtual destructor then is left? If there is a derived class, you need to use another approach: remove call to Perform from the constructor, and change all callers of this class, as it is done with math_BFGS in the fix for #0025719.
I suggest using the same general behavior of all math computation classes, and leaving them polymorphic. For that we should make the fix as proposed in the bug description: "suppressing call to Perform method from the constructor".
If this method is called only from Perform and no more virtual, why not to make it inline?
src\math\math_NewtonMinimum.cdl:62 is a strange line, looks like a mistake. If you want to leave empty virtual destructor than define some non-virtual inline stub method and make alias virtual destructor calling this stub.
src\math\math_NewtonMinimum.cxx
The virtual method IsConverged is no more called. So, virtual mechanism is no more used. Why virtual destructor then is left? If there is a derived class, you need to use another approach: remove call to Perform from the constructor, and change all callers of this class, as it is done with math_BFGS in the fix for #0025719.
I suggest using the same general behavior of all math computation classes, and leaving them polymorphic. For that we should make the fix as proposed in the bug description: "suppressing call to Perform method from the constructor".
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
Please review.
src\math\math_FRPR.cdl
- English grammar in "constructor isn't performs computations".
Correct is "constructor doesn't perform computations".
- Ctor with theStartingPoint is extra, as Perform is to be called in any case.
src\math\math_NewtonMinimum.cdl
- English grammar in "This constructor not perform computation".
Correct is "This constructor does not perform computation".
src\GeomFill\GeomFill_LocationGuide.cxx
- 360-361: indentation is broken (consider tab size = 8 characters, and not 2).
It is also needed to make fix in occt-products due to API changes.
- English grammar in "constructor isn't performs computations".
Correct is "constructor doesn't perform computations".
- Ctor with theStartingPoint is extra, as Perform is to be called in any case.
src\math\math_NewtonMinimum.cdl
- English grammar in "This constructor not perform computation".
Correct is "This constructor does not perform computation".
src\GeomFill\GeomFill_LocationGuide.cxx
- 360-361: indentation is broken (consider tab size = 8 characters, and not 2).
It is also needed to make fix in occt-products due to API changes.
Small correction: it is better to use complete wording "does not" instead of abbreviated form "doesn't" which is used to represent spoken language. The only exclusion, to my knowledge, is "let's".
Branch [archived branch] has been updated by Participant.
[revision removed]
Detailed log of new commits:
Author: azn
Date: Thu Jan 29 08:54:14 2015 +0300
0025720: Incorrect code of math classes can lead to unpredicted behavior of algorithms
Small grammar fixes.
[revision removed]
Detailed log of new commits:
Author: azn
Date: Thu Jan 29 08:54:14 2015 +0300
0025720: Incorrect code of math classes can lead to unpredicted behavior of algorithms
Small grammar fixes.
There is no direct dependencies between occt and products.
Reviewed.
Dear Commenter 1,
Branch CR25720 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested in Release mode.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 18 (18 on master)
Windows: 0 (0 on master)
products component :
Linux: 11 (11 on master)
Windows: 1 (1 on master)
Regressions/Differences:
No regressions
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 369654500 / 370114884
Total CPU difference: 52887.95000000013 / 51750.710000000094
Testing on Windows:
Total MEMORY difference: 276204336 / 275761696
Total CPU difference: 38970.984375 / 38148.203125
There are not differences in images found by testdiff.
Branch CR25720 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested in Release mode.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 18 (18 on master)
Windows: 0 (0 on master)
products component :
Linux: 11 (11 on master)
Windows: 1 (1 on master)
Regressions/Differences:
No regressions
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 369654500 / 370114884
Total CPU difference: 52887.95000000013 / 51750.710000000094
Testing on Windows:
Total MEMORY difference: 276204336 / 275761696
Total CPU difference: 38970.984375 / 38148.203125
There are not differences in images found by testdiff.
Dear AZN,
Could you please to rebase CR25720 to current master. I got a lot of conflicts.
Could you please to rebase CR25720 to current master. I got a lot of conflicts.
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
Brunch has been rebased. Please check.
Please squash commits into one and make actual comment.
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
Reviewed.
Dear Commenter 1,
Branch CR26720 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component:
Linux: 18 (18 on master)
Windows: 0 (0 on master)
products component:
Linux: 11 (11 on master)
Windows: 1 (1 on master)
Regressions/Differences:
Not detected
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 86055997 / 86186549
Total CPU difference: 49467.680000000124 / 47876.709999999846
Testing on Windows:
Total MEMORY difference: 40648352 / 40658496
Total CPU difference: 37627.515625 / 32754.0
Branch CR26720 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component:
Linux: 18 (18 on master)
Windows: 0 (0 on master)
products component:
Linux: 11 (11 on master)
Windows: 1 (1 on master)
Regressions/Differences:
Not detected
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 86055997 / 86186549
Total CPU difference: 49467.680000000124 / 47876.709999999846
Testing on Windows:
Total MEMORY difference: 40648352 / 40658496
Total CPU difference: 37627.515625 / 32754.0
Branch [archived branch] has been updated forcibly by Author.
[revision removed]
[revision removed]
Branch [archived branch] has been deleted by Participant.
[revision removed]
[revision removed]
Related records
- #0025719 · related to · closedBoolean operations can crash
- #0025622 · related to · closedCAST analysis: Avoid invocation of virtual Methods of the declared Class in a Constructor or Destructor
- #0025577 · related to · closedAvoid invocation of virtual Methods of the declared Class in a Constructor or Destructor