Fix #964 (Integer division by zero exception)
http://sourceforge.net/apps/trac/cppcheck/ticket/964
This commit is contained in:
parent
f569edc614
commit
9275b49688
|
@ -678,6 +678,8 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
|
|||
// malloc() gets count of bytes and not count of
|
||||
// elements, so we should calculate count of elements
|
||||
// manually
|
||||
unsigned int sizeOfType = _tokenizer->sizeOfType(declTok);
|
||||
if (sizeOfType > 0)
|
||||
size /= _tokenizer->sizeOfType(declTok);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,6 +134,7 @@ private:
|
|||
TEST_CASE(memset1);
|
||||
TEST_CASE(counter_test);
|
||||
TEST_CASE(strncpy1);
|
||||
TEST_CASE(unknownType);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1335,6 +1336,15 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
|
||||
}
|
||||
|
||||
void unknownType()
|
||||
{
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" UnknownType *a = malloc(4);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestBufferOverrun)
|
||||
|
|
Loading…
Reference in New Issue