[clang] [-Wunsafe-buffer-usage] Fix false warnings when const sized array is safely accessed (array [idx %const]) (PR #140113)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 15 10:55:49 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp -- clang/lib/Analysis/UnsafeBufferUsage.cpp clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 2f669637a..ec648e1a1 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -606,13 +606,13 @@ static bool isSafeArraySubscript(const ArraySubscriptExpr &Node,
const Expr *LHS = BE->getLHS();
const Expr *RHS = BE->getRHS();
- if(BE->getOpcode() == BO_Rem) {
+ if (BE->getOpcode() == BO_Rem) {
// If n is a negative number, then n % const can be greater than const
- if(!LHS->getType()->isUnsignedIntegerType()) {
+ if (!LHS->getType()->isUnsignedIntegerType()) {
return false;
}
- if(!RHS->isValueDependent() && RHS->EvaluateAsInt(EVResult, Ctx)) {
+ if (!RHS->isValueDependent() && RHS->EvaluateAsInt(EVResult, Ctx)) {
llvm::APSInt result = EVResult.Val.getInt();
if (result.isNonNegative() && result.getLimitedValue() <= limit)
return true;
``````````
</details>
https://github.com/llvm/llvm-project/pull/140113
More information about the cfe-commits
mailing list