]> granicus.if.org Git - clang/commitdiff
[analyzer] Do not attempt to get the pointee of void*
authorAlexander Shaposhnikov <shal1t712@gmail.com>
Wed, 24 Jan 2018 22:17:30 +0000 (22:17 +0000)
committerAlexander Shaposhnikov <shal1t712@gmail.com>
Wed, 24 Jan 2018 22:17:30 +0000 (22:17 +0000)
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

lib/StaticAnalyzer/Core/PathDiagnostic.cpp
test/Analysis/malloc.c

index fd3de613840da2937493a0d9d8c5282e8dbf1234..2b041241623e45c7a6ec9fda0b1cb4fb71f9b124 100644 (file)
@@ -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) {
index 6e3f3faaa1768c6c8a2fb0a03f0a03a6ce4a6d6e..50be4ef3ba2903b9f995f84ce598985c6a83897a 100644 (file)
@@ -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.