-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[NFC] Fix potential underflow constant. #118528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clang-tidy Author: Zahira Ammarguellat (zahiraam) ChangesIf the range for Full diff: https://github.com/llvm/llvm-project/pull/118528.diff 1 Files Affected:
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>
|
| ->getTemplateParameters() | ||
| ->getParam(Idx - 1) | ||
| : nullptr; | ||
| return AnyOf && Idx > 0 ? CRTP->getSpecializedTemplate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's possible for AnyOf to be true and Idx to be 0 at the same time. Idx starts as zero, but the call to any_of on line 54 has a lambda which explicitly does ++Idx, so any_of cannot return true without incrementing Idx.
If this came from a static analysis tool, I would claim it's a false positive that doesn't require changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if the range is empty Idx will be incremented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the range is empty, then Idx is not incremented, but AnyOf will be false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closing the PR then. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the noise.
|
If the range for
llvm::any_ofis empty,Idxwill be0and an underflow might occur when computingIdx-1.