Fix 10621: FP arrayIndexOutOfBoundsCond with multiple index checks (#3640)
This commit is contained in:
parent
ffae40d2f4
commit
e7db974606
|
@ -1225,12 +1225,17 @@ static void valueFlowArray(TokenList *tokenlist)
|
|||
setTokenValue(tok, value, tokenlist->getSettings());
|
||||
}
|
||||
|
||||
// const array decl
|
||||
else if (tok->variable() && tok->variable()->isArray() && tok->variable()->isConst() &&
|
||||
tok->variable()->nameToken() == tok && Token::Match(tok, "%var% [ %num%| ] = {")) {
|
||||
const Token* rhstok = tok->next()->link()->tokAt(2);
|
||||
constantArrays[tok->varId()] = rhstok;
|
||||
tok = rhstok->link();
|
||||
}
|
||||
|
||||
// pointer = array
|
||||
else if (tok->variable() &&
|
||||
tok->variable()->isArray() &&
|
||||
Token::simpleMatch(tok->astParent(), "=") &&
|
||||
tok == tok->astParent()->astOperand2() &&
|
||||
tok->astParent()->astOperand1() &&
|
||||
else if (tok->variable() && tok->variable()->isArray() && Token::simpleMatch(tok->astParent(), "=") &&
|
||||
astIsRHS(tok) && tok->astParent()->astOperand1() &&
|
||||
tok->astParent()->astOperand1()->variable() &&
|
||||
tok->astParent()->astOperand1()->variable()->isPointer()) {
|
||||
ValueFlow::Value value;
|
||||
|
|
|
@ -1743,6 +1743,17 @@ private:
|
|||
" return M[i];\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("struct S { enum E { e0 }; };\n"
|
||||
"const S::E M[4] = { S::E:e0, S::E:e0, S::E:e0, S::E:e0 };\n"
|
||||
"int f(int i) {\n"
|
||||
" if (i > std::size(M) + 1)\n"
|
||||
" return -1;\n"
|
||||
" if (i < 0 || i >= std::size(M))\n"
|
||||
" return 0;\n"
|
||||
" return M[i]; \n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void array_index_multidim() {
|
||||
|
|
Loading…
Reference in New Issue