build: handle nil Options in largeFilesFlag
The flag package may call the String method with a zero-valued receiver,
such as a nil pointer. For example this happens when passing in the flag
"-help", so this fixes a panic in that case. This was a panic introduced
in 5dd4713 build: factor out build flags.
Change-Id: I27e5b66637fe2f3ad8231baa3e5b355b579e052f
diff --git a/build/builder.go b/build/builder.go
index ab4efcb..6c35e50 100644
--- a/build/builder.go
+++ b/build/builder.go
@@ -100,6 +100,13 @@
type largeFilesFlag struct{ *Options }
func (f largeFilesFlag) String() string {
+ // From flag.Value documentation:
+ //
+ // The flag package may call the String method with a zero-valued receiver,
+ // such as a nil pointer.
+ if f.Options == nil {
+ return ""
+ }
s := append([]string{""}, f.LargeFiles...)
return strings.Join(s, "-large_file ")
}