[clang-tools-extra] 5bc13f9 - [clang-tidy] ProBoundsConstantArrayIndexCheck::check - use cast<> instead of dyn_cast<> to avoid dereference of nullptr
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 12 02:48:29 PST 2022
Author: Simon Pilgrim
Date: 2022-02-12T10:43:21Z
New Revision: 5bc13f9d9471adc81c8bf2b62775b6e2fd72f8e6
URL: https://github.com/llvm/llvm-project/commit/5bc13f9d9471adc81c8bf2b62775b6e2fd72f8e6
DIFF: https://github.com/llvm/llvm-project/commit/5bc13f9d9471adc81c8bf2b62775b6e2fd72f8e6.diff
LOG: [clang-tidy] ProBoundsConstantArrayIndexCheck::check - use cast<> instead of dyn_cast<> to avoid dereference of nullptr
The pointer is referenced immediately, so assert the cast is correct instead of returning nullptr
Added:
Modified:
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
index 59886ee4a3ebc..d7bc56511dfb5 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
@@ -71,7 +71,7 @@ void ProBoundsConstantArrayIndexCheck::check(
BaseRange = ArraySubscriptE->getBase()->getSourceRange();
else
BaseRange =
- dyn_cast<CXXOperatorCallExpr>(Matched)->getArg(0)->getSourceRange();
+ cast<CXXOperatorCallExpr>(Matched)->getArg(0)->getSourceRange();
SourceRange IndexRange = IndexExpr->getSourceRange();
auto Diag = diag(Matched->getExprLoc(),
More information about the cfe-commits
mailing list