Fixed #5863 (False positive: array index is used before limits check)

This commit is contained in:
PKEuS 2014-05-24 17:48:08 +02:00
parent bb8973aac7
commit effa38c322
2 changed files with 7 additions and 1 deletions

View File

@ -2102,7 +2102,7 @@ void CheckBufferOverrun::arrayIndexThenCheck()
// statement can be closed in parentheses, so "(| " is using
if (Token::Match(tok, "&& (| %varid% <|<=", indexID))
arrayIndexThenCheckError(tok, indexName);
else if (Token::Match(tok, "&& (| %any% >|>= %varid%", indexID))
else if (Token::Match(tok, "&& (| %any% >|>= %varid% !!+", indexID))
arrayIndexThenCheckError(tok, indexName);
}
}

View File

@ -3976,6 +3976,12 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", errout.str());
check("void f(char* e, int y) {\n"
" if (e[y] == '/' && elen > y + 1 && e[y + 1] == '?') {\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
// this one doesn't work for now, hopefully in the future
check("void f(const int a[], unsigned i) {\n"
" if(a[i] < func(i) && i <= 42) {\n"