-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Partial fix for #15048 (conditional containerOutOfBounds) #8881
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -371,7 +371,7 @@ class TestStl : public TestFixture { | |
| " return s[x];\n" | ||
| "}\n"); | ||
| ASSERT_EQUALS( | ||
| "[test.cpp:5:13]: error: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 7 [containerOutOfBounds]\n", | ||
| "[test.cpp:5:13]: warning: Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 7 [containerOutOfBounds]\n", | ||
| errout_str()); | ||
|
|
||
| checkNormal("void f() {\n" | ||
|
|
@@ -534,7 +534,7 @@ class TestStl : public TestFixture { | |
| " v.resize(entries);\n" | ||
| " v[0] = 1;\n" | ||
| "}\n"); | ||
| ASSERT_EQUALS("[test.cpp:5:6]: error: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\n", errout_str()); | ||
| ASSERT_EQUALS("[test.cpp:5:6]: warning: Out of bounds access in expression 'v[0]' because 'v' is empty. [containerOutOfBounds]\n", errout_str()); | ||
|
|
||
| checkNormal("void f(size_t entries) {\n" | ||
| " if (entries < 2) return;\n" | ||
|
|
@@ -760,7 +760,7 @@ class TestStl : public TestFixture { | |
| " v[i] = 42;\n" | ||
| " return v;\n" | ||
| "}\n"); | ||
| ASSERT_EQUALS("[test.cpp:4:10]: error: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\n", | ||
| ASSERT_EQUALS("[test.cpp:4:10]: warning: Out of bounds access in 'v[i]', if 'v' size is 10 and 'i' is 10 [containerOutOfBounds]\n", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an AI review take it with a grain of salt. Please feel free to reject it by clicking on Resolve button The change only lowers the severity, so it can't add false positives, and it matches what As you noted, this #10779 case is a definite bug (the loop always reaches |
||
| errout_str()); | ||
|
|
||
| check("void f() {\n" | ||
|
|
@@ -1154,6 +1154,27 @@ class TestStl : public TestFixture { | |
| "[test.cpp:3:29]: note: Assuming that condition 'it!=v.end()' is not redundant\n" | ||
| "[test.cpp:7:7]: note: Either the condition is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds.\n", | ||
| errout_str()); | ||
|
|
||
| check("char f(std::string& s, bool b) {\n" | ||
| " if (b)\n" | ||
| " s.clear();\n" | ||
| " return s[0];\n" | ||
| "}\n" | ||
| "char g(bool b) {\n" | ||
| " std::string s = \"abc\";\n" | ||
| " int i = 0;\n" | ||
| " if (b)\n" | ||
| " i = 5;\n" | ||
| " return s[i];\n" | ||
| "}\n", s); | ||
| ASSERT_EQUALS("[test.cpp:4:13]: warning: Out of bounds access in expression 's[0]' because 's' is empty. [containerOutOfBounds]\n" | ||
| "[test.cpp:2:9]: note: Assuming condition is true\n" | ||
| "[test.cpp:4:13]: note: Access out of bounds\n" | ||
| "[test.cpp:11:13]: warning: Out of bounds access in 's[i]', if 's' size is 3 and 'i' is 5 [containerOutOfBounds]\n" | ||
| "[test.cpp:10:13]: note: Assignment 'i=5', assigned value is 5\n" | ||
| "[test.cpp:9:9]: note: Assuming condition is true\n" | ||
| "[test.cpp:11:13]: note: Access out of bounds\n", | ||
| errout_str()); | ||
| } | ||
|
|
||
| void iterator1() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a ValueFlow issue, even known loop iterations have conditional values.