]> granicus.if.org Git - clang/commitdiff
[CStringSyntaxChecker] Fix build bot builds != x86 archs
authorDavid Carlier <devnexen@gmail.com>
Fri, 20 Jul 2018 20:39:49 +0000 (20:39 +0000)
committerDavid Carlier <devnexen@gmail.com>
Fri, 20 Jul 2018 20:39:49 +0000 (20:39 +0000)
Reviewers: NoQ,george.karpenkov

Reviewed By: NoQ

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

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

lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
test/Analysis/cstring-syntax.c

index 6654e822e1ce16d0bc18a6748daed897175e240a..b1f37f5a342a2be6b5e3c4897fa5d00e192e6a31 100644 (file)
@@ -147,7 +147,7 @@ bool WalkAST::containsBadStrlcpyPattern(const CallExpr *CE) {
   const Expr *DstArg = CE->getArg(0);
   const Expr *LenArg = CE->getArg(2);
 
-  const auto *DstArgDecl = dyn_cast<DeclRefExpr>(DstArg->IgnoreParenCasts());
+  const auto *DstArgDecl = dyn_cast<DeclRefExpr>(DstArg->IgnoreParenImpCasts());
   const auto *LenArgDecl = dyn_cast<DeclRefExpr>(LenArg->IgnoreParenLValueCasts());
   // - size_t dstlen = sizeof(dst)
   if (LenArgDecl) {
@@ -159,14 +159,15 @@ bool WalkAST::containsBadStrlcpyPattern(const CallExpr *CE) {
   // - integral value
   // We try to figure out if the last argument is possibly longer
   // than the destination can possibly handle if its size can be defined
-  if (const auto *IL = dyn_cast<IntegerLiteral>(LenArg->IgnoreParenCasts())) {
+  if (const auto *IL = dyn_cast<IntegerLiteral>(LenArg->IgnoreParenImpCasts())) {
     uint64_t ILRawVal = IL->getValue().getZExtValue();
-    if (const auto *Buffer = dyn_cast<ConstantArrayType>(DstArgDecl->getType())) {
-      ASTContext &C = BR.getContext();
-      uint64_t Usize = C.getTypeSizeInChars(DstArg->getType()).getQuantity();
-      uint64_t BufferLen = BR.getContext().getTypeSize(Buffer) / Usize;
-      if (BufferLen < ILRawVal)
-        return true;
+    if (DstArgDecl) {
+      if (const auto *Buffer = dyn_cast<ConstantArrayType>(DstArgDecl->getType())) {
+        ASTContext &C = BR.getContext();
+        uint64_t BufferLen = C.getTypeSize(Buffer) / 8;
+        if (BufferLen < ILRawVal)
+          return true;
+      }
     }
   }
 
index d7df3f082c6760ec6628807e76323d4b59fda3e5..f64682b418d1720b6685c7f4d9054ad2ad8dc548 100644 (file)
@@ -1,4 +1,7 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=unix.cstring.BadSizeArg -analyzer-store=region -Wno-strncat-size -Wno-strlcpy-strlcat-size -Wno-sizeof-array-argument -Wno-sizeof-pointer-memaccess -verify %s
+// RUN: %clang_analyze_cc1 -triple armv7-a15-linux -analyzer-checker=unix.cstring.BadSizeArg -analyzer-store=region -Wno-strncat-size -Wno-strlcpy-strlcat-size -Wno-sizeof-array-argument -Wno-sizeof-pointer-memaccess -verify %s
+// RUN: %clang_analyze_cc1 -triple aarch64_be-none-linux-gnu -analyzer-checker=unix.cstring.BadSizeArg -analyzer-store=region -Wno-strncat-size -Wno-strlcpy-strlcat-size -Wno-sizeof-array-argument -Wno-sizeof-pointer-memaccess -verify %s
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -analyzer-checker=unix.cstring.BadSizeArg -analyzer-store=region -Wno-strncat-size -Wno-strlcpy-strlcat-size -Wno-sizeof-array-argument -Wno-sizeof-pointer-memaccess -verify %s
 
 typedef __SIZE_TYPE__ size_t;
 char  *strncat(char *, const char *, size_t);
@@ -27,4 +30,5 @@ void testStrlcpy(const char *src) {
   strlcpy(dest, src, 20); // expected-warning {{The third argument is larger than the size of the input buffer. Replace with the value 'sizeof(dest)` or lower}}
   strlcpy(dest, src, badlen); // expected-warning {{The third argument is larger than the size of the input buffer. Replace with the value 'sizeof(dest)` or lower}}
   strlcpy(dest, src, ulen);
+  strlcpy(dest + 5, src, 5);
 }