Hello,
Seems like nobody ran experimental.unix.cstring.BadSizeArg on any C++
source, because it crashed for me on iostream. Attached is the patch
that fixes that and introduces a testcase.
Dmitri Gribenko
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <[email protected]>*/
Index: test/Analysis/cstring-syntax-cxx.cpp
===================================================================
--- test/Analysis/cstring-syntax-cxx.cpp (revision 0)
+++ test/Analysis/cstring-syntax-cxx.cpp (revision 0)
@@ -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;
+}
+
Index: lib/StaticAnalyzer/Core/CheckerContext.cpp
===================================================================
--- lib/StaticAnalyzer/Core/CheckerContext.cpp (revision 149513)
+++ lib/StaticAnalyzer/Core/CheckerContext.cpp (working copy)
@@ -53,7 +53,13 @@
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);
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits