Fixed #1021 (Out-of-bounds access false positive)
This commit is contained in:
parent
6e175053c1
commit
f75c9619d1
|
@ -766,6 +766,8 @@ void CheckBufferOverrun::checkStructVariable()
|
||||||
varname[1] = tok2->strAt(ivar);
|
varname[1] = tok2->strAt(ivar);
|
||||||
int arrsize = std::atoi(tok2->strAt(ivar + 2));
|
int arrsize = std::atoi(tok2->strAt(ivar + 2));
|
||||||
int total_size = arrsize * _tokenizer->sizeOfType(tok2->tokAt(1));
|
int total_size = arrsize * _tokenizer->sizeOfType(tok2->tokAt(1));
|
||||||
|
if (tok2->tokAt(2)->str() == "*")
|
||||||
|
total_size = arrsize * sizeof(void *);
|
||||||
if (total_size == 0)
|
if (total_size == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -133,6 +133,7 @@ private:
|
||||||
TEST_CASE(alloc); // Buffer allocated with new
|
TEST_CASE(alloc); // Buffer allocated with new
|
||||||
|
|
||||||
TEST_CASE(memset1);
|
TEST_CASE(memset1);
|
||||||
|
TEST_CASE(memset2);
|
||||||
TEST_CASE(counter_test);
|
TEST_CASE(counter_test);
|
||||||
TEST_CASE(strncpy1);
|
TEST_CASE(strncpy1);
|
||||||
TEST_CASE(unknownType);
|
TEST_CASE(unknownType);
|
||||||
|
@ -1282,6 +1283,18 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void memset2()
|
||||||
|
{
|
||||||
|
check("class X {\n"
|
||||||
|
" char* array[2];\n"
|
||||||
|
" X();\n"
|
||||||
|
"};\n"
|
||||||
|
"X::X() {\n"
|
||||||
|
" memset(array, 0, sizeof(array));\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void counter_test()
|
void counter_test()
|
||||||
{
|
{
|
||||||
std::list<const Token*> unknownParameter;
|
std::list<const Token*> unknownParameter;
|
||||||
|
|
Loading…
Reference in New Issue