]> granicus.if.org Git - clang/commitdiff
[analyzer] Fix a crash in CheckerContext::isCLibraryFunction for C++
authorAnna Zaks <ganna@apple.com>
Wed, 1 Feb 2012 19:16:20 +0000 (19:16 +0000)
committerAnna Zaks <ganna@apple.com>
Wed, 1 Feb 2012 19:16:20 +0000 (19:16 +0000)
declarations with special names.

A patch by Dmitri Gribenko.

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

lib/StaticAnalyzer/Core/CheckerContext.cpp
test/Analysis/cstring-syntax-cxx.cpp [new file with mode: 0644]

index ccf415f0c71a3b01cf8b2e4e6c97b36eb4a0a04d..6ad4162b8f044415ee04174be2bd379352a628e9 100644 (file)
@@ -53,7 +53,13 @@ bool CheckerContext::isCLibraryFunction(const FunctionDecl *FD,
       return true;
   }
 
-  StringRef FName = FD->getIdentifier()->getName();
+  const IdentifierInfo *II = FD->getIdentifier();
+  // If this is a special C++ name without IdentifierInfo, it can't be a
+  // C library function.
+  if (!II)
+    return false;
+
+  StringRef FName = II->getName();
   if (FName.startswith("__inline"))
     return (FName.find(Name) != StringRef::npos);
 
diff --git a/test/Analysis/cstring-syntax-cxx.cpp b/test/Analysis/cstring-syntax-cxx.cpp
new file mode 100644 (file)
index 0000000..af8b4d7
--- /dev/null
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=experimental.unix.cstring.BadSizeArg -analyzer-store=region -verify %s
+
+// Ensure we don't crash on C++ declarations with special names.
+struct X {
+  X(int i): i(i) {}
+  int i;
+};
+
+X operator+(X a, X b) {
+  return X(a.i + b.i);
+}
+
+void test(X a, X b) {
+  X c = a + b;
+}
+