-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang][NFC] Add nullptr check in InitializationSequence::InitializeFrom #143067
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
Static analysis flagged that Var could be nullptr but we were not checking in the branch and unconditionally dereferences the pointer.
@llvm/pr-subscribers-clang Author: Shafik Yaghmour (shafik) ChangesStatic analysis flagged that Var could be nullptr but we were not checking in the branch and unconditionally dereferences the pointer. Note, code was added by 576161c Full diff: https://github.com/llvm/llvm-project/pull/143067.diff 1 Files Affected:
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 5d870f07093ec..da56225b2f926 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -6620,7 +6620,7 @@ void InitializationSequence::InitializeFrom(Sema &S,
// initializer present. However, we only do this for structure types, not
// union types, because an unitialized field in a union is generally
// reasonable, especially in C where unions can be used for type punning.
- if (!Initializer && !Rec->isUnion() && !Rec->isInvalidDecl()) {
+ if (Var && !Initializer && !Rec->isUnion() && !Rec->isInvalidDecl()) {
if (const FieldDecl *FD = getConstField(Rec)) {
unsigned DiagID = diag::warn_default_init_const_field_unsafe;
if (Var->getStorageDuration() == SD_Static ||
|
If this were a bug, I suspect it would have been reported. |
It could but that feel like a weak argument, I would like something stronger. We do |
llvm-project/clang/lib/Sema/SemaInit.cpp Line 3728 in e4060d3
|
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.
LGTM
…rom (llvm#143067) Static analysis flagged that Var could be nullptr but we were not checking in the branch and unconditionally dereferences the pointer. Note, code was added by 576161c
…rom (llvm#143067) Static analysis flagged that Var could be nullptr but we were not checking in the branch and unconditionally dereferences the pointer. Note, code was added by 576161c
…rom (llvm#143067) Static analysis flagged that Var could be nullptr but we were not checking in the branch and unconditionally dereferences the pointer. Note, code was added by 576161c
Static analysis flagged that Var could be nullptr but we were not checking in the branch and unconditionally dereferences the pointer.
Note, code was added by 576161c