[clang-tools-extra] [NFC] Fix potential underflow constant. (PR #118528)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 3 12:06:12 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tidy
Author: Zahira Ammarguellat (zahiraam)
<details>
<summary>Changes</summary>
If the range for `llvm::any_of` is empty, `Idx` will be `0` and an underflow might occur when computing `Idx-1`.
---
Full diff: https://github.com/llvm/llvm-project/pull/118528.diff
1 Files Affected:
- (modified) clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp (+4-4)
``````````diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp
index 8eaf54fe0088a4..ce307a2384aef7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp
@@ -58,10 +58,10 @@ getDerivedParameter(const ClassTemplateSpecializationDecl *CRTP,
Arg.getAsType()->getAsCXXRecordDecl() == Derived;
});
- return AnyOf ? CRTP->getSpecializedTemplate()
- ->getTemplateParameters()
- ->getParam(Idx - 1)
- : nullptr;
+ return AnyOf && Idx > 0 ? CRTP->getSpecializedTemplate()
+ ->getTemplateParameters()
+ ->getParam(Idx - 1)
+ : nullptr;
}
static std::vector<FixItHint>
``````````
</details>
https://github.com/llvm/llvm-project/pull/118528
More information about the cfe-commits
mailing list