Fix #947 (Errors not detected when size_t is used instead of int)

http://sourceforge.net/apps/trac/cppcheck/ticket/947
This commit is contained in:
Reijo Tomperi 2009-11-12 23:31:13 +02:00
parent 0518eed937
commit 3d5760b149
3 changed files with 13 additions and 1 deletions

View File

@ -529,7 +529,7 @@ size_t Token::getStrLength(const Token *tok)
bool Token::isStandardType() const
{
bool ret = false;
const char *type[] = {"bool", "char", "short", "int", "long", "float", "double", 0};
const char *type[] = {"bool", "char", "short", "int", "long", "float", "double", "size_t", 0};
for (int i = 0; type[i]; i++)
ret |= (_str == type[i]);
return ret;

View File

@ -1600,6 +1600,7 @@ void Tokenizer::simplifySizeof()
_typeSize["long"] = sizeof(long);
_typeSize["float"] = sizeof(float);
_typeSize["double"] = sizeof(double);
_typeSize["size_t"] = sizeof(size_t);
_typeSize["*"] = sizeof(void *);
for (Token *tok = _tokens; tok; tok = tok->next())

View File

@ -90,6 +90,7 @@ private:
TEST_CASE(array_index_19);
TEST_CASE(array_index_20);
TEST_CASE(array_index_21);
TEST_CASE(array_index_22);
TEST_CASE(array_index_multidim);
TEST_CASE(buffer_overrun_1);
@ -669,6 +670,16 @@ private:
ASSERT_EQUALS("", errout.str());
}
void array_index_22()
{
check("#include <cstring>\n"
"int main() {\n"
" size_t indices[2];\n"
" int b = indices[2];\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Array index out of bounds\n", errout.str());
}
void array_index_multidim()
{
check("void f()\n"