Skip to content

Conversation

zahiraam
Copy link
Contributor

@zahiraam zahiraam commented Oct 9, 2025

This is a find from static analysis tool complaining about potential constant overflow for Index.

@zahiraam zahiraam marked this pull request as ready for review October 9, 2025 13:28
@llvmbot
Copy link
Member

llvmbot commented Oct 9, 2025

@llvm/pr-subscribers-clang-tidy

@llvm/pr-subscribers-clang-tools-extra

Author: Zahira Ammarguellat (zahiraam)

Changes

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 --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]);

@zahiraam zahiraam changed the title [NFC][clang-tidy] Fix potential constant overflow [Clang-tidy][NFC] Fix potential constant overflow Oct 9, 2025
@zahiraam zahiraam requested a review from carlosgalvezp October 9, 2025 13:45
@zahiraam
Copy link
Contributor Author

zahiraam commented Oct 9, 2025

Thanks @vbvictor!

@zahiraam zahiraam merged commit 17fe934 into llvm:main Oct 9, 2025
15 checks passed
svkeerthy pushed a commit that referenced this pull request Oct 9, 2025
This is a find from static analysis tool complaining about potential
constant overflow for `Index`.
clingfei pushed a commit to clingfei/llvm-project that referenced this pull request Oct 10, 2025
This is a find from static analysis tool complaining about potential
constant overflow for `Index`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants