Fix #1296 (false positive: index out of bounds)

http://sourceforge.net/apps/trac/cppcheck/ticket/1296
This commit is contained in:
Reijo Tomperi 2010-01-20 21:26:54 +02:00
parent 863a42797f
commit b83d257852
2 changed files with 2 additions and 1 deletions

View File

@ -4187,7 +4187,7 @@ bool Tokenizer::simplifyCalculations()
if (Token::Match(tok->previous(), "- %num% - %num%"))
tok->str(MathLib::calculate(tok->str(), tok->tokAt(2)->str(), '+'));
else if (Token::Match(tok->previous(), "- %num% + %num%"))
tok->str(MathLib::calculate(tok->tokAt(2)->str(), tok->str(), '-'));
tok->str(MathLib::calculate(tok->str(), tok->tokAt(2)->str(), '-'));
else
tok->str(MathLib::calculate(tok->str(), tok->tokAt(2)->str(), *(tok->strAt(1))));

View File

@ -1940,6 +1940,7 @@ private:
ASSERT_EQUALS("x = 900 ;", tok("x = 1500000 / ((145000 - 55000) * 1000 / 54000);"));
ASSERT_EQUALS("int a [ 8 ] ;", tok("int a[5+6/2];"));
ASSERT_EQUALS("int a [ 4 ] ;", tok("int a[(10)-1-5];"));
ASSERT_EQUALS("int a [ i - 9 ] ;", tok("int a[i - 10 + 1];"));
}