[clang-tools-extra] 17fe934 - [Clang-tidy][NFC] Fix potential constant overflow (#162647)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 9 08:24:31 PDT 2025
Author: Zahira Ammarguellat
Date: 2025-10-09T10:42:25-04:00
New Revision: 17fe934c3df3745e12977b9f4f470857e4494723
URL: https://github.com/llvm/llvm-project/commit/17fe934c3df3745e12977b9f4f470857e4494723
DIFF: https://github.com/llvm/llvm-project/commit/17fe934c3df3745e12977b9f4f470857e4494723.diff
LOG: [Clang-tidy][NFC] Fix potential constant overflow (#162647)
This is a find from static analysis tool complaining about potential
constant overflow for `Index`.
Added:
Modified:
clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp
Removed:
################################################################################
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]);
More information about the cfe-commits
mailing list