New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Path counting incorrect for conditional statements with return #125
Comments
Thanks for spotting & reporting. I'll take a look in the near future if you don't have any success. |
I'm still puzzled about how to do that properly. It looks easier to count paths on a control flow graph / acyclic graph than on the AST - but that's what we've got. I've looked around and didn't find much (asides from enterprise tools that I couldn't test). OClint ignores the returns as well as checkstyle (a java static analyzer). An if statement with an return in one case should not be treated as x2 by a compound statement with multiple statement, but a first try to count it as x1 and additional sum up the returns didn't work either. |
Interesting paper by a company selling static analysis and metrics tools: Looks like you've correctly implemented NPath as described in the original 1988 paper, but that doesn't account for early returns. |
Rework path counting, fix for #125
Fixed by merged pull request. |
If a conditional statement always exits the function, it should not be treated as a path multiplier.
Example: PATH = 32 (2 ^ 5), but should be 6 (5+1) -- one of the 5 ifs is entered or none.
I'm looking at MetricsMatcher.cpp, which already tracks if all subpaths have returns, but I haven't figured out, how to fix it yet. Will keep trying.
The text was updated successfully, but these errors were encountered: