-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[NFC] Fix potential nullptr dereference. #138283
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) ChangesA Full diff: https://github.com/llvm/llvm-project/pull/138283.diff 1 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.cpp
index 247d287be2b36..e90170a6591da 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.cpp
@@ -25,6 +25,7 @@ void RedundantFunctionPtrDereferenceCheck::registerMatchers(MatchFinder *Finder)
void RedundantFunctionPtrDereferenceCheck::check(const MatchFinder::MatchResult &Result) {
const auto *Operator = Result.Nodes.getNodeAs<UnaryOperator>("op");
+ assert(Operator && "Operator is null");
diag(Operator->getOperatorLoc(),
"redundant repeated dereference of function pointer")
<< FixItHint::CreateRemoval(Operator->getOperatorLoc());
|
|
Did you run code sanitizer over all clang-tidy code or you only interested in this particular file? llvm-project/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp Lines 39 to 43 in 52d2b58
llvm-project/clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp Lines 51 to 52 in 52d2b58
|
Probably. But we usually stick to the potential issues suggested by the sanitizer. |
nicovank
left a comment
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.
This is not needed IMO. This is a simple matcher, op is expected to always be bound.
One might say that it can't hurt to add extra checks, but I don't think that's good justification for adding more code / bloat, even if in this case it's a single line. Still, 5% more code for this check counting non-empty non-comment lines!
Happy to disagree if any of the maintainers think otherwise.
The sanitizer is complaining about the possibility of having |
|
I don't have a strong opinion on this, but this |
|
|
Thanks for your input. I will close this PR. |
A
nullptrdereference is detected by the code sanitizer. Adding an assert to make sure it's caught.