Skip to content

Commit 3715814

Browse files
zahiraamsvkeerthy
authored andcommitted
[Clang-tidy][NFC] Fix potential constant overflow (#162647)
This is a find from static analysis tool complaining about potential constant overflow for `Index`.
1 parent d81510c commit 3715814

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ static FixItHint generateFixItHint(const ObjCPropertyDecl *Decl,
3939
auto NewName = Decl->getName().str();
4040
size_t Index = 0;
4141
if (Style == CategoryProperty) {
42-
Index = Name.find_first_of('_') + 1;
43-
NewName.replace(0, Index - 1, Name.substr(0, Index - 1).lower());
42+
size_t UnderScorePos = Name.find_first_of('_');
43+
if (UnderScorePos != llvm::StringRef::npos) {
44+
Index = UnderScorePos + 1;
45+
NewName.replace(0, Index - 1, Name.substr(0, Index - 1).lower());
46+
}
4447
}
4548
if (Index < Name.size()) {
4649
NewName[Index] = tolower(NewName[Index]);

0 commit comments

Comments
 (0)