service: Handle zero-value in stringPtrFlag.String

FlagSet.PrintDefaults uses reflection to construct a zero value, calls
.String on it, and compares the result with the current flag value to
detect zero-value flags. For stringPtrFlag, this would result in a
panic, as String() always dereferenced the first level of its **string.

Add another check so that both pointer levels are nil-checked.
This commit is contained in:
Kenny Levinsen 2020-06-10 14:13:19 +02:00 committed by Simon Ser
parent 18250311b9
commit 1cbdb26dd1
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -250,7 +250,7 @@ type stringPtrFlag struct {
}
func (f stringPtrFlag) String() string {
if *f.ptr == nil {
if f.ptr == nil || *f.ptr == nil {
return ""
}
return **f.ptr