Skip to content
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

Closed
mringwal opened this issue Mar 12, 2020 · 4 comments
Closed

Path counting incorrect for conditional statements with return #125

mringwal opened this issue Mar 12, 2020 · 4 comments

Comments

@mringwal
Copy link
Contributor

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.

void fn_ifs_with_return(int i){
    if (i == 1){
        // i == 1
        return;
    }
    if (i == 2){
        // i == 2
        return;
    }
    if (i == 3){
        // i == 3
        return;
    }
    if (i == 4){
        // i == 4
        return;
    }
    if (i == 5){
        // i == 5
        return;
    }
}

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.

@bright-tools
Copy link
Owner

Thanks for spotting & reporting. I'll take a look in the near future if you don't have any success.

@mringwal
Copy link
Contributor Author

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.

@mringwal
Copy link
Contributor Author

Interesting paper by a company selling static analysis and metrics tools:
https://arxiv.org/pdf/1610.07914.pdf

Looks like you've correctly implemented NPath as described in the original 1988 paper, but that doesn't account for early returns.

bright-tools added a commit that referenced this issue Jun 21, 2020
Rework path counting, fix for #125
@mringwal
Copy link
Contributor Author

Fixed by merged pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants