From: Alexander Shaposhnikov Date: Wed, 24 Jan 2018 22:17:30 +0000 (+0000) Subject: [analyzer] Do not attempt to get the pointee of void* X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=738efbf68e94662f720b03712831aa2840a69761;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@323382 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp index fd3de61384..2b04124162 100644 --- a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp +++ b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp @@ -1211,6 +1211,9 @@ std::string StackHintGeneratorForSymbol::getMessage(const ExplodedNode *N){ // Check if the parameter is a pointer to the symbol. if (Optional Reg = SV.getAs()) { + // 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) { diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c index 6e3f3faaa1..50be4ef3ba 100644 --- a/test/Analysis/malloc.c +++ b/test/Analysis/malloc.c @@ -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.