[analyzer] Do not attempt to get the pointee of void*
Do not attempt to get the pointee of void* while generating a bug report (otherwise it will trigger an assert inside RegionStoreManager::getBinding assert(!T->isVoidType() && "Attempting to dereference a void pointer!")). Test plan: make check-all Differential revision: https://reviews.llvm.org/D42396 llvm-svn: 323382
This commit is contained in:
parent
61f4ac98e0
commit
0c352b15d7
|
@ -1211,6 +1211,9 @@ std::string StackHintGeneratorForSymbol::getMessage(const ExplodedNode *N){
|
|||
|
||||
// Check if the parameter is a pointer to the symbol.
|
||||
if (Optional<loc::MemRegionVal> Reg = SV.getAs<loc::MemRegionVal>()) {
|
||||
// Do not attempt to dereference void*.
|
||||
if ((*I)->getType()->isVoidPointerType())
|
||||
continue;
|
||||
SVal PSV = N->getState()->getSVal(Reg->getRegion());
|
||||
SymbolRef AS = PSV.getAsLocSymbol();
|
||||
if (AS == Sym) {
|
||||
|
|
|
@ -1786,6 +1786,18 @@ void cstringchecker_bounds_nocrash() {
|
|||
free(p);
|
||||
}
|
||||
|
||||
void allocateSomeMemory(void *offendingParameter, void **ptr) {
|
||||
*ptr = malloc(1);
|
||||
}
|
||||
|
||||
void testNoCrashOnOffendingParameter() {
|
||||
// "extern" is necessary to avoid unrelated warnings
|
||||
// on passing uninitialized value.
|
||||
extern void *offendingParameter;
|
||||
void* ptr;
|
||||
allocateSomeMemory(offendingParameter, &ptr);
|
||||
} // expected-warning {{Potential leak of memory pointed to by 'ptr'}}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// False negatives.
|
||||
|
||||
|
|
Loading…
Reference in New Issue