[clang] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files (PR #109496)
Ziqing Luo via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 20 19:36:00 PDT 2024
================
@@ -784,12 +786,12 @@ AST_MATCHER_P(CallExpr, hasUnsafePrintfStringArg,
return false; // possibly some user-defined printf function
ASTContext &Ctx = Finder->getASTContext();
- QualType FristParmTy = FD->getParamDecl(0)->getType();
+ QualType FirstParmTy = FD->getParamDecl(0)->getType();
- if (!FristParmTy->isPointerType())
+ if (!FirstParmTy->isPointerType())
return false; // possibly some user-defined printf function
- QualType FirstPteTy = (cast<PointerType>(FristParmTy))->getPointeeType();
+ QualType FirstPteTy = FirstParmTy->getAs<PointerType>()->getPointeeType();
----------------
ziqingluo-90 wrote:
The difference between `castAs` and `getAs` is that `castAs` asserts the canonical type is `PointerType` while `getAs` returns null if not. I think `castAs` is more suitable for our case.
https://github.com/llvm/llvm-project/pull/109496
More information about the cfe-commits
mailing list