From 9c9801e69114b582b12aa7010c75fe2105ae23b3 Mon Sep 17 00:00:00 2001 From: chressie Date: Fri, 17 Mar 2023 12:01:04 +0100 Subject: [PATCH] glog: make zero value of vModuleFlag usable The flag package ensures that the zero value of a flag.Value is usable. This commit fixes this. This was raised in https://groups.google.com/g/golang-nuts/c/Atlr8uAjn6U/m/iId17Td5BQAJ. cl/517349579 (google-internal) --- glog_flags.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/glog_flags.go b/glog_flags.go index fc486455..fa4371af 100644 --- a/glog_flags.go +++ b/glog_flags.go @@ -133,6 +133,11 @@ func (l *Level) Set(value string) error { type vModuleFlag struct{ *verboseFlags } func (f vModuleFlag) String() string { + // Do not panic on the zero value. + // https://groups.google.com/g/golang-nuts/c/Atlr8uAjn6U/m/iId17Td5BQAJ. + if f.verboseFlags == nil { + return "" + } f.mu.Lock() defer f.mu.Unlock()