[PATCH] D43928: [analyzer] Correctly measure array size in security.insecureAPI.strcpy

AndrĂ¡s Leitereg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 1 00:20:57 PST 2018


leanil created this revision.
leanil added reviewers: dcoughlin, xazax.hun, NoQ.
Herald added subscribers: a.sidorin, rnkovacs, szepet.
Herald added a reviewer: george.karpenkov.

This will handle those platforms that don't have 8-bit chars.
This is a follow up fix to review https://reviews.llvm.org/D41384, which has been committed since.


https://reviews.llvm.org/D43928

Files:
  lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp


Index: lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
+++ lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
@@ -514,7 +514,7 @@
              *Source = CE->getArg(1)->IgnoreImpCasts();
   if (const auto *DeclRef = dyn_cast<DeclRefExpr>(Target))
     if (const auto *Array = dyn_cast<ConstantArrayType>(DeclRef->getType())) {
-      uint64_t ArraySize = BR.getContext().getTypeSize(Array) / 8;
+      uint64_t ArraySize = BR.getContext().getTypeSizeInChars(Array).getQuantity();
       if (const auto *String = dyn_cast<StringLiteral>(Source)) {
         if (ArraySize >= String->getLength() + 1)
           return;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43928.136473.patch
Type: text/x-patch
Size: 758 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180301/67ac2341/attachment.bin>


More information about the cfe-commits mailing list