[PATCH] D41384: [analyzer] Suppress false positive warnings form security.insecureAPI.strcpy

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 12 12:08:50 PST 2018


NoQ added inline comments.


================
Comment at: lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp:517
+    if (const auto *Array = dyn_cast<ConstantArrayType>(
+            DeclRef->getDecl()->getType().getTypePtr())) {
+      unsigned long long ArraySize = Array->getSize().getLimitedValue();
----------------
leanil wrote:
> NoQ wrote:
> > This can be simplified to `const auto *Array = DeclRef->getType()->getAs<ConstantArrayType>()`.
> > `.getTypePtr()` is almost always redundant because of the fancy `operator->()` on `QualType`.
> Using `getAs` yielded: 
> > error: static assertion failed: ArrayType cannot be used with getAs!
> 
> 
Whoops, yeah, right, array types are the rare exception. It should be `ASTContext.getAsConstantArrayType()`, see the docs for `getAsArrayType()` for some explanation of why it was made this way. I guess we don't really care about these aspects, so your code is fine :)


https://reviews.llvm.org/D41384





More information about the cfe-commits mailing list