From 1cbdb26dd1dd4f97c8ac1178d143fb76bc8c58ce Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Wed, 10 Jun 2020 14:13:19 +0200 Subject: [PATCH] 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. --- service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service.go b/service.go index ef708e1..85dfe19 100644 --- a/service.go +++ b/service.go @@ -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