[clang-tools-extra] [NFC][clang-tidy] Fix potential constant overflow (PR #162647)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 9 06:29:15 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: Zahira Ammarguellat (zahiraam)
<details>
<summary>Changes</summary>
This is a find from static analysis tool complaining about potential constant overflow for `Index`.
---
Full diff: https://github.com/llvm/llvm-project/pull/162647.diff
1 Files Affected:
- (modified) clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp (+5-2)
``````````diff
diff --git a/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp b/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp
index f2bc6f10b9c58..4a586c8ff0ac9 100644
--- a/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -39,8 +39,11 @@ static FixItHint generateFixItHint(const ObjCPropertyDecl *Decl,
auto NewName = Decl->getName().str();
size_t Index = 0;
if (Style == CategoryProperty) {
- Index = Name.find_first_of('_') + 1;
- NewName.replace(0, Index - 1, Name.substr(0, Index - 1).lower());
+ size_t UnderScorePos = Name.find_first_of('_');
+ if (UnderScorePos != llvm::StringRef::npos) {
+ Index = UnderScorePos + 1;
+ NewName.replace(0, Index - 1, Name.substr(0, Index - 1).lower());
+ }
}
if (Index < Name.size()) {
NewName[Index] = tolower(NewName[Index]);
``````````
</details>
https://github.com/llvm/llvm-project/pull/162647
More information about the cfe-commits
mailing list