Fixed #8721 (Regression: False positive array index out of bounds)
This commit is contained in:
parent
c7e5176284
commit
f388c77042
|
@ -1297,6 +1297,10 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
|
|||
negativeMemoryAllocationSizeError(tok);
|
||||
}
|
||||
|
||||
/** @todo false negatives: this may be too conservative */
|
||||
if (!var || !var->isPointer() || var->typeStartToken()->next() != var->typeEndToken())
|
||||
continue;
|
||||
|
||||
// malloc() gets count of bytes and not count of
|
||||
// elements, so we should calculate count of elements
|
||||
// manually
|
||||
|
|
|
@ -3093,6 +3093,13 @@ private:
|
|||
" tab4[20] = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'tab4[20]' accessed at index 20, which is out of bounds.\n", errout.str());
|
||||
|
||||
check("void f() {\n" // #8721
|
||||
" unsigned char **cache = malloc(32);\n"
|
||||
" cache[i] = malloc(65536);\n"
|
||||
" cache[i][0xFFFF] = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// statically allocated buffer
|
||||
|
|
Loading…
Reference in New Issue