From b83d257852469728a4d91e4b433e386e4bf0053a Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Wed, 20 Jan 2010 21:26:54 +0200 Subject: [PATCH] Fix #1296 (false positive: index out of bounds) http://sourceforge.net/apps/trac/cppcheck/ticket/1296 --- lib/tokenize.cpp | 2 +- test/testsimplifytokens.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5ca2c6e0c..eee3ed0f1 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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)))); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index e0b08ec0f..dca2d6995 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -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];")); }