Fix 10643: FP: (error) Array 'buf[64]' accessed at index -1, which is out of bounds. (#3639)

* Fix 10643: FP: (error) Array 'buf[64]' accessed at index -1, which is out of bounds.

* Format
This commit is contained in:
Paul Fultz II 2021-12-17 03:05:57 -06:00 committed by GitHub
parent 398fa28021
commit 4fb43a3f56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -5544,7 +5544,7 @@ struct ConditionHandler {
bool dead_if = deadBranch[0];
bool dead_else = deadBranch[1];
const Token* unknownFunction = nullptr;
if (tok->astParent() && Token::simpleMatch(tok->astParent()->previous(), "while ("))
if (tok->astParent() && Token::Match(top->previous(), "while|for ("))
dead_if = !isBreakScope(after);
else if (!dead_if)
dead_if = isReturnScope(after, &settings->library, &unknownFunction);

View File

@ -187,6 +187,7 @@ private:
TEST_CASE(array_index_negative1);
TEST_CASE(array_index_negative2); // ticket #3063
TEST_CASE(array_index_negative3);
TEST_CASE(array_index_negative4);
TEST_CASE(array_index_for_decr);
TEST_CASE(array_index_varnames); // FP: struct member. #1576
TEST_CASE(array_index_for_continue); // for,continue
@ -2031,6 +2032,17 @@ private:
ASSERT_EQUALS("", errout.str());
}
void array_index_negative4()
{
check("void f(void) {\n"
" int buf[64]={};\n"
" int i;\n"
" for(i=0; i <16; ++i){}\n"
" for(; i < 24; ++i){ buf[i] = buf[i-16];}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void array_index_for_decr() {
check("void f()\n"
"{\n"