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

Fix #12318 FP negativeIndex with do while loop #6720

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/forwardanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ namespace {
if (!checkThen && !checkElse && !isDoWhile && stopOnCondition(condTok) && stopUpdates())
return Break(Analyzer::Terminate::Conditional);
// condition is false, we don't enter the loop
if (checkElse)
if (checkElse && !isDoWhile)
return Progress::Continue;
if (checkThen || isDoWhile) {
// Since we are re-entering the loop then assume the condition is true to update the state
Expand Down
12 changes: 12 additions & 0 deletions test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2799,6 +2799,18 @@ class TestBufferOverrun : public TestFixture {
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 's>sizeof(a)' is redundant or the array 'a[16]' is accessed at index 16, which is out of bounds.\n",
errout_str());

check("void f(int fd) {\n" // #12318
" char buf[10];\n"
" int size = 0;\n"
" int pos = -1;\n"
" do {\n"
" pos++;\n"
" size = read(fd, &buf[pos], 1);\n"
" } while (size > 0);\n"
" buf[pos] = '\\0';\n"
"}\n");
ASSERT_EQUALS("", errout_str());

}

void array_index_valueflow_pointer() {
Expand Down
Loading