From 9a48efec00f0f4a38367c61f1c19bdcd1512e02d Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 3 Oct 2009 21:27:16 +0700 Subject: [PATCH] Fixed #775 (###### If you see this, there is a bug ###### Token::Match() - varid was 0) http://sourceforge.net/apps/trac/cppcheck/ticket/775 --- src/checkbufferoverrun.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/checkbufferoverrun.cpp b/src/checkbufferoverrun.cpp index ecfac9d24..a80733576 100644 --- a/src/checkbufferoverrun.cpp +++ b/src/checkbufferoverrun.cpp @@ -252,18 +252,18 @@ void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], con continue; int value = 0; - if (counter_varid) + if (counter_varid == 0) + continue; + + if (Token::Match(tok2, "%varid% < %num% ;", counter_varid)) { - if (Token::Match(tok2, "%varid% < %num% ;", counter_varid)) - { - value = std::atoi(tok2->strAt(2)); - max_counter_value = MathLib::toString(value - 1); - } - else if (Token::Match(tok2, "%varid% <= %num% ;", counter_varid)) - { - value = std::atoi(tok2->strAt(2)) + 1; - max_counter_value = tok2->strAt(2); - } + value = std::atoi(tok2->strAt(2)); + max_counter_value = MathLib::toString(value - 1); + } + else if (Token::Match(tok2, "%varid% <= %num% ;", counter_varid)) + { + value = std::atoi(tok2->strAt(2)) + 1; + max_counter_value = tok2->strAt(2); } // Get index variable and stopsize.