cmd/gotext: fix segfault in extract & rewrite commands
If extract or rewrite are called with no arguments it results in a
segmentation fault, since we dereference the out flag that was
not defined for these commands.
Fixes golang/go#62697
Change-Id: I697943b7c221431d0361bcec74c18183f6e141ea
GitHub-Last-Rev: 313ddfad2b9a43d4fbaa875fa4dd3110dcf38083
GitHub-Pull-Request: golang/text#46
Reviewed-on: https://go-review.googlesource.com/c/text/+/529255
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
diff --git a/cmd/gotext/main.go b/cmd/gotext/main.go
index ed0f7ec..5171eb1 100644
--- a/cmd/gotext/main.go
+++ b/cmd/gotext/main.go
@@ -48,11 +48,18 @@
if err != nil {
return nil, wrap(err, "invalid srclang")
}
+
+ // Use a default value since rewrite and extract don't have an out flag.
+ genFile := ""
+ if out != nil {
+ genFile = *out
+ }
+
return &pipeline.Config{
SourceLanguage: tag,
Supported: getLangs(),
TranslationsPattern: `messages\.(.*)\.json$`,
- GenFile: *out,
+ GenFile: genFile,
Dir: *dir,
}, nil
}