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,7 +678,9 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
|
||||||
// malloc() gets count of bytes and not count of
|
// malloc() gets count of bytes and not count of
|
||||||
// elements, so we should calculate count of elements
|
// elements, so we should calculate count of elements
|
||||||
// manually
|
// manually
|
||||||
size /= _tokenizer->sizeOfType(declTok);
|
unsigned int sizeOfType = _tokenizer->sizeOfType(declTok);
|
||||||
|
if (sizeOfType > 0)
|
||||||
|
size /= _tokenizer->sizeOfType(declTok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -134,6 +134,7 @@ private:
|
||||||
TEST_CASE(memset1);
|
TEST_CASE(memset1);
|
||||||
TEST_CASE(counter_test);
|
TEST_CASE(counter_test);
|
||||||
TEST_CASE(strncpy1);
|
TEST_CASE(strncpy1);
|
||||||
|
TEST_CASE(unknownType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1335,6 +1336,15 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
|
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)
|
REGISTER_TEST(TestBufferOverrun)
|
||||||
|
|
|
@ -1143,11 +1143,11 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkUninitVar("int f(int (*assign)(char *p))\n"
|
checkUninitVar("int f(int (*assign)(char *p))\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
" (*assign)(&i);\n"
|
" (*assign)(&i);\n"
|
||||||
" return i;\n"
|
" return i;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// arrays..
|
// arrays..
|
||||||
|
|
Loading…
Reference in New Issue