Skip to content

Commit 0c352b1

Browse files
committedJan 24, 2018
[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
1 parent 61f4ac9 commit 0c352b1

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
 

‎clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,9 @@ std::string StackHintGeneratorForSymbol::getMessage(const ExplodedNode *N){
12111211

12121212
// Check if the parameter is a pointer to the symbol.
12131213
if (Optional<loc::MemRegionVal> Reg = SV.getAs<loc::MemRegionVal>()) {
1214+
// Do not attempt to dereference void*.
1215+
if ((*I)->getType()->isVoidPointerType())
1216+
continue;
12141217
SVal PSV = N->getState()->getSVal(Reg->getRegion());
12151218
SymbolRef AS = PSV.getAsLocSymbol();
12161219
if (AS == Sym) {

‎clang/test/Analysis/malloc.c

+12
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,18 @@ void cstringchecker_bounds_nocrash() {
17861786
free(p);
17871787
}
17881788

1789+
void allocateSomeMemory(void *offendingParameter, void **ptr) {
1790+
*ptr = malloc(1);
1791+
}
1792+
1793+
void testNoCrashOnOffendingParameter() {
1794+
// "extern" is necessary to avoid unrelated warnings
1795+
// on passing uninitialized value.
1796+
extern void *offendingParameter;
1797+
void* ptr;
1798+
allocateSomeMemory(offendingParameter, &ptr);
1799+
} // expected-warning {{Potential leak of memory pointed to by 'ptr'}}
1800+
17891801
// ----------------------------------------------------------------------------
17901802
// False negatives.
17911803

0 commit comments

Comments
 (0)
Please sign in to comment.