r338775 - [analyzer] Add a safety check to InnerPointerChecker.

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 3 03:53:01 PDT 2018


On Fri, Aug 3, 2018 at 12:20 AM Reka Kovacs via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> Author: rkovacs
> Date: Thu Aug  2 15:19:57 2018
> New Revision: 338775
>
> URL: http://llvm.org/viewvc/llvm-project?rev=338775&view=rev
> Log:
> [analyzer] Add a safety check to InnerPointerChecker.
>
> Do not crash if the CXXRecordDecl of an object is not available.
>
> Modified:
>     cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp?rev=338775&r1=338774&r2=338775&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
> (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp Thu Aug
> 2 15:19:57 2018
> @@ -129,8 +129,11 @@ bool InnerPointerChecker::isCalledOnStri
>      return false;
>
>    QualType ObjTy = ObjRegion->getValueType();
> -  if (ObjTy.isNull() ||
> -      ObjTy->getAsCXXRecordDecl()->getName() != "basic_string")
> +  if (ObjTy.isNull())
> +    return false;
> +
> +  CXXRecordDecl *Decl = ObjTy->getAsCXXRecordDecl();
> +  if (!Decl || Decl->getName() != "basic_string")
>      return false;
>
>    return true;
>

Thanks for the fix! An improvement suggestion:
return Decl && Decl->getName() == "basic_string";


>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180803/f12dc1e4/attachment.html>


More information about the cfe-commits mailing list