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:
parent
0518eed937
commit
3d5760b149
|
@ -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;
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue