Skip to content

Fix some false positive in loop forward analysis#2669

Merged
danmar merged 2 commits into
cppcheck-opensource:masterfrom
Ken-Patrick:false_loop_condition_forward_analysis
Jun 5, 2020
Merged

Fix some false positive in loop forward analysis#2669
danmar merged 2 commits into
cppcheck-opensource:masterfrom
Ken-Patrick:false_loop_condition_forward_analysis

Conversation

@Ken-Patrick

Copy link
Copy Markdown
Contributor

In cases like:

bool b();
void f()
{
    int val[50];
    int i, sum=0;
    for (i = 1; b() && i < 50; i++)
        sum += val[i];
    for (; i < 50; i++)
        sum -= val[i];
}

The forward analysis assumed the second loop was entered, and we ended
up with false positive in it:
Array 'val[50]' accessed at index 50, which is out of bounds

In cases like:
```
bool b();
void f()
{
    int val[50];
    int i, sum=0;
    for (i = 1; b() && i < 50; i++)
        sum += val[i];
    for (; i < 50; i++)
        sum -= val[i];
}
```
The forward analysis assumed the second loop was entered, and we ended
up with false positive in it:
 `Array 'val[50]' accessed at index 50, which is out of bounds`
@amai2012 amai2012 requested a review from danmar June 5, 2020 07:39
@danmar danmar merged commit 8c2c81d into cppcheck-opensource:master Jun 5, 2020
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

Successfully merging this pull request may close these issues.

2 participants