-
Notifications
You must be signed in to change notification settings - Fork 10
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
fix: nil pointers identified by nilaway (part 1) #512
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,8 +33,14 @@ type GlobalFlags struct { | |
} | ||
|
||
func NewGlobalFlags() *GlobalFlags { | ||
var name string | ||
if os.Args == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it actually possible for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like it is possible, but I don't think it can ever happen in practice. |
||
name = "gouroboros" | ||
} else { | ||
name = os.Args[0] | ||
} | ||
f := &GlobalFlags{ | ||
Flagset: flag.NewFlagSet(os.Args[0], flag.ExitOnError), | ||
Flagset: flag.NewFlagSet(name, flag.ExitOnError), | ||
} | ||
f.Flagset.StringVar( | ||
&f.Socket, | ||
|
@@ -71,6 +77,10 @@ func NewGlobalFlags() *GlobalFlags { | |
} | ||
|
||
func (f *GlobalFlags) Parse() { | ||
if os.Args == nil { | ||
fmt.Printf("failed to parse command line\n") | ||
os.Exit(1) | ||
} | ||
if err := f.Flagset.Parse(os.Args[1:]); err != nil { | ||
fmt.Printf("failed to parse command args: %s\n", err) | ||
os.Exit(1) | ||
|
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 upstream vendored code. We should probably add a comment here
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.
Why is this vendored instead of being imported?
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 think it was to avoid the flood of deps from importing
https://github.com/btcsuite/btcd