Skip to content

MVG will not accurate when if statement follow up with return statements #9

@JiahangLi

Description

@JiahangLi

It's a great open source Cyclomatic Complexity tool with extensive details about the program.
However, I found some issue while using it to test out our project. Here is a simple function that would help to illustrate the problem.

int main (){
    int a ,b ;
    a = 26; 
    b =10;
    if (a > 10 ||b < 45 && (a+b)< 55){
        return 1;
    } 
    return 2;
}

I might be wrong, but as far as I concern, this function should score MVG = 4, since we have three decision points while the measurement result by CCCC would be MVG = 5.

Thus, I did some experiment about it.

  1. MVG will go down to 4, if I remove the "return 2;" statement.
  2. MVG will go down to 4, if the "return 1;" replaced by other code instead of a return statement.

It can lead to a big error rate, since some of big functions include several if statements and sprinkled with return statement as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions