[PATCH] D39422: [analyzer] pr34779: CStringChecker: Don't get crashed by non-standard standard library function definitions.

Phabricator via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 7 02:51:53 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL317565: [analyzer] pr34779: CStringChecker: Accept non-standard headers. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D39422?vs=120834&id=121866#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39422

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  cfe/trunk/test/Analysis/string-with-signedness.c


Index: cfe/trunk/test/Analysis/string-with-signedness.c
===================================================================
--- cfe/trunk/test/Analysis/string-with-signedness.c
+++ cfe/trunk/test/Analysis/string-with-signedness.c
@@ -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);
+}
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -289,8 +289,8 @@
   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 @@
   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");
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39422.121866.patch
Type: text/x-patch
Size: 1470 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171107/b054cc93/attachment.bin>


More information about the cfe-commits mailing list