Fix #1392 (Segfault in CheckBufferOverrun::checkScope)

http://sourceforge.net/apps/trac/cppcheck/ticket/1392
This commit is contained in:
Reijo Tomperi 2010-02-15 23:20:09 +02:00
parent e9e5174797
commit e44f0b1b8d
2 changed files with 17 additions and 3 deletions

View File

@ -1,6 +1,6 @@
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2009 Daniel MarjamŠki and Cppcheck team.
* Copyright (C) 2007-2009 Daniel Marjamäki and Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -340,7 +340,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
if (counter_varid == 0)
continue;
const Token *strindextoken;
const Token *strindextoken = 0;
if (Token::Match(tok2, "%varid% < %num% ;", counter_varid))
{
value = MathLib::toLongNumber(tok2->strAt(2));
@ -367,6 +367,10 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
value = MathLib::toLongNumber(max_counter_value.c_str());
strindextoken = tok2->tokAt(2);
}
else
{
continue;
}
// Get index variable and stopsize.
const char *strindex = strindextoken->str().c_str();

View File

@ -332,8 +332,18 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
}
}
{
check("void foo(int argc)\n"
"{\n"
" char a[2];\n"
" for (int i = 4; i < argc; i++)\n"
" {\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
}
void array_index_4()
{