diff --git a/src/checkbufferoverrun.cpp b/src/checkbufferoverrun.cpp index 8c5d789ad..946c79cfe 100644 --- a/src/checkbufferoverrun.cpp +++ b/src/checkbufferoverrun.cpp @@ -248,13 +248,16 @@ void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], con else continue; - if (Token::Match(tok2, "%varid% < %num% ;", counter_varid)) + if (counter_varid) { - max_counter_value = MathLib::toString(atol(tok2->strAt(2)) - 1); - } - else if (Token::Match(tok2, "%varid% <= %num% ;", counter_varid)) - { - max_counter_value = tok2->strAt(2); + if (Token::Match(tok2, "%varid% < %num% ;", counter_varid)) + { + max_counter_value = MathLib::toString(atol(tok2->strAt(2)) - 1); + } + else if (Token::Match(tok2, "%varid% <= %num% ;", counter_varid)) + { + max_counter_value = tok2->strAt(2); + } } // Get index variable and stopsize.