soju: service: Handle zero-value in stringPtrFlag.String v1 APPLIED

Kenny Levinsen: 1
 service: Handle zero-value in stringPtrFlag.String

 1 files changed, 1 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/public-inbox/patches/10976/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH soju] service: Handle zero-value in stringPtrFlag.String Export this patch

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