Opened 8 years ago
Closed 8 years ago
#10985 closed Bugs (fixed)
Logically dead code; dubious source code comment / inverted if condition?
Reported by: | Owned by: | John Maddock | |
---|---|---|---|
Milestone: | To Be Determined | Component: | math |
Version: | Boost 1.57.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Static code analysis with Coverity pointed me to some dead code in the function ibeta_imp in boost/math/special_functions/beta.hpp. My system's boost library is 1.55.0, but the issue is present identically in boost 1.57. In a block guarded by
if (normalised) {
there is the following line (number 1224):
fract -= (normalised ? 1 : boost::math::beta(a, b, pol));
Clearly, normalised has to be true due to the if guard thus the second part (boost::math::beta(a, b, pos)) will never be used.
Furthermore, it may be that the if guard's condition is missing a negation for which there are two indications:
- in the vicinity (i.e. in the function ibeta_imp) most other if statements (6 of 7) that involve normalised check if normalised is not set (i.e. "if(!normalised)"), and
- more importantly, the first comment in that block on lines 1211-1213 reads:
1209: else if(normalised) 1210: { 1211: // the formula here for the non-normalised case is tricky to figure 1212: // out (for me!!), and requires two pochhammer calculations rather 1213: // than one, so leave it for now....
I apologize for my limited understanding of the details of the code, which precludes me from proposing a fix, but something seems fishy here!
Finally, the line subsequent to the one with the dead code, i.e. line 1225, contains a commented-out alternative. This indicates to me that this entire block may not have been fully satisfactory to the original author(s).
Fixed in https://github.com/boostorg/math/commit/20965d162e0b6ae6f3308bceb3bfc5f27d43b031
The logic in the branch is correct - I had originally intenbded this branch to handle both normalized and not cases, but couldn't get the non-normalized case working correctly so it got excluded without tidying up the now-dead code.