]> granicus.if.org Git - clang/commitdiff
[analyzer] pr34779: CStringChecker: Accept non-standard headers.
authorArtem Dergachev <artem.dergachev@gmail.com>
Tue, 7 Nov 2017 10:51:15 +0000 (10:51 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Tue, 7 Nov 2017 10:51:15 +0000 (10:51 +0000)
Do not crash when trying to define and call a non-standard
strcpy(unsigned char *, unsigned char *) during analysis.

At the same time, do not try to actually evaluate the call.

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

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

lib/StaticAnalyzer/Checkers/CStringChecker.cpp
test/Analysis/string-with-signedness.c [new file with mode: 0644]

index 58218df23881c73a793ff737c73c32df5dbb21dc..28ad7e9e5071d6321e6bc07d3f3d93f8c71c764d 100644 (file)
@@ -289,8 +289,8 @@ ProgramStateRef CStringChecker::CheckLocation(CheckerContext &C,
   if (!ER)
     return state;
 
-  assert(ER->getValueType() == C.getASTContext().CharTy &&
-    "CheckLocation should only be called with char* ElementRegions");
+  if (ER->getValueType() != C.getASTContext().CharTy)
+    return state;
 
   // Get the size of the array.
   const SubRegion *superReg = cast<SubRegion>(ER->getSuperRegion());
@@ -874,6 +874,8 @@ bool CStringChecker::IsFirstBufInBound(CheckerContext &C,
   if (!ER)
     return true; // cf top comment.
 
+  // FIXME: Does this crash when a non-standard definition
+  // of a library function is encountered?
   assert(ER->getValueType() == C.getASTContext().CharTy &&
          "IsFirstBufInBound should only be called with char* ElementRegions");
 
diff --git a/test/Analysis/string-with-signedness.c b/test/Analysis/string-with-signedness.c
new file mode 100644 (file)
index 0000000..1b00971
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -Wno-incompatible-library-redeclaration -analyzer-checker=core,unix.cstring,alpha.unix.cstring -verify %s
+
+// expected-no-diagnostics
+
+void *strcpy(unsigned char *, unsigned char *);
+
+unsigned char a, b;
+void testUnsignedStrcpy() {
+  strcpy(&a, &b);
+}