Fixed #2311 (False positive: Index out of bounds)

This commit is contained in:
Daniel Marjamäki 2010-12-16 20:16:59 +01:00
parent eb0231b48f
commit 2d97189486
2 changed files with 20 additions and 0 deletions

View File

@ -6092,6 +6092,10 @@ bool Tokenizer::simplifyKnownVariables()
if (pointeralias && Token::Match(tok3, ("!!= " + value).c_str()))
break;
// Stop if do is found
if (tok3->str() == "do")
break;
// Stop if something like 'while (--var)' is found
if (tok3->str() == "for" || tok3->str() == "while" || tok3->str() == "do")
{

View File

@ -120,6 +120,7 @@ private:
TEST_CASE(simplifyKnownVariables31);
TEST_CASE(simplifyKnownVariables32); // const
TEST_CASE(simplifyKnownVariables33); // struct variable
TEST_CASE(simplifyKnownVariables34);
TEST_CASE(simplifyKnownVariablesBailOutAssign);
TEST_CASE(simplifyKnownVariablesBailOutFor1);
TEST_CASE(simplifyKnownVariablesBailOutFor2);
@ -1852,6 +1853,21 @@ private:
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
}
void simplifyKnownVariables34()
{
const char code[] = "void f() {\n"
" int x = 10;\n"
" do { cin >> x; } while (x > 5);\n"
" a[x] = 0;\n"
"}\n";
const char expected[] = "void f ( ) {\n"
"int x ; x = 10 ;\n"
"do { cin >> x ; } while ( 5 < x ) ;\n"
"a [ x ] = 0 ;\n"
"}";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
}
void simplifyKnownVariablesBailOutAssign()
{
const char code[] = "int foo() {\n"