]> granicus.if.org Git - clang/commitdiff
[analyzer] MallocChecker: Fix one more bug category.
authorArtem Dergachev <artem.dergachev@gmail.com>
Thu, 8 Feb 2018 23:28:29 +0000 (23:28 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Thu, 8 Feb 2018 23:28:29 +0000 (23:28 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@324680 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/MallocChecker.cpp
test/Analysis/malloc-fnptr-plist.c [new file with mode: 0644]

index a1a540c4b96ea948741d427addbce6cb8f0b9f8f..378728dc6131017d9aefca090d9b0d2853d6ab24 100644 (file)
@@ -2075,8 +2075,8 @@ void MallocChecker::ReportFunctionPointerFree(CheckerContext &C, SVal ArgVal,
 
   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);
diff --git a/test/Analysis/malloc-fnptr-plist.c b/test/Analysis/malloc-fnptr-plist.c
new file mode 100644 (file)
index 0000000..6490eeb
--- /dev/null
@@ -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>