r324680 - [analyzer] MallocChecker: Fix one more bug category.

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 8 15:28:29 PST 2018


Author: dergachev
Date: Thu Feb  8 15:28:29 2018
New Revision: 324680

URL: http://llvm.org/viewvc/llvm-project?rev=324680&view=rev
Log:
[analyzer] MallocChecker: Fix one more bug category.

Even though most of the inconsistencies in MallocChecker's bug categories were
fixed in r302016, one more was introduced in r301913 which was later missed.

Patch by Henry Wong!

Differential Revision: https://reviews.llvm.org/D43074

Added:
    cfe/trunk/test/Analysis/malloc-fnptr-plist.c
Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=324680&r1=324679&r2=324680&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Thu Feb  8 15:28:29 2018
@@ -2075,8 +2075,8 @@ void MallocChecker::ReportFunctionPointe
 
   if (ExplodedNode *N = C.generateErrorNode()) {
     if (!BT_BadFree[*CheckKind])
-      BT_BadFree[*CheckKind].reset(
-          new BugType(CheckNames[*CheckKind], "Bad free", "Memory Error"));
+      BT_BadFree[*CheckKind].reset(new BugType(
+          CheckNames[*CheckKind], "Bad free", categories::MemoryError));
 
     SmallString<100> Buf;
     llvm::raw_svector_ostream Os(Buf);

Added: cfe/trunk/test/Analysis/malloc-fnptr-plist.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc-fnptr-plist.c?rev=324680&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/malloc-fnptr-plist.c (added)
+++ cfe/trunk/test/Analysis/malloc-fnptr-plist.c Thu Feb  8 15:28:29 2018
@@ -0,0 +1,11 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker core,unix.Malloc -analyzer-output=plist -o %t.plist -verify %s
+// RUN: FileCheck --input-file=%t.plist %s
+
+void free(void *);
+void (*fnptr)(int);
+void foo() {
+  free((void *)fnptr); // expected-warning{{Argument to free() is a function pointer}}
+}
+
+// Make sure the bug category is correct.
+// CHECK: <key>category</key><string>Memory error</string>




More information about the cfe-commits mailing list