From: Mateusz Poliwczak Date: Sat, 8 Feb 2025 13:59:18 +0000 (+0000) Subject: cmd/compile/internal/gc: handle errors from *bio.Writer X-Git-Tag: go1.25rc1~1097 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c8664ced4ef61456a98acb9f910b1646ae81e3b5;p=gostls13.git cmd/compile/internal/gc: handle errors from *bio.Writer The error is stored internally in *bio.Writer, more specifically in *bufio.Writer and the current code does not handle it, ignoring errors silently. Change-Id: Iefa9bf7ddabb3c4fc03377e676a8098dcad9be6d GitHub-Last-Rev: a5d36223312773039c37bb1c52fffc96fff04fba GitHub-Pull-Request: golang/go#71621 Reviewed-on: https://go-review.googlesource.com/c/go/+/647915 Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall Reviewed-by: Dmitri Shuralyov Auto-Submit: Keith Randall --- diff --git a/src/cmd/compile/internal/gc/export.go b/src/cmd/compile/internal/gc/export.go index c93f008ba2..9afbeb9d3b 100644 --- a/src/cmd/compile/internal/gc/export.go +++ b/src/cmd/compile/internal/gc/export.go @@ -47,5 +47,7 @@ func dumpasmhdr() { } } - b.Close() + if err := b.Close(); err != nil { + base.Fatalf("%v", err) + } } diff --git a/src/cmd/compile/internal/gc/obj.go b/src/cmd/compile/internal/gc/obj.go index 4b42c81ef8..37bbce0318 100644 --- a/src/cmd/compile/internal/gc/obj.go +++ b/src/cmd/compile/internal/gc/obj.go @@ -57,7 +57,7 @@ func dumpobj1(outfile string, mode int) { fmt.Printf("can't create %s: %v\n", outfile, err) base.ErrorExit() } - defer bout.Close() + bout.WriteString("!\n") if mode&modeCompilerObj != 0 { @@ -70,6 +70,12 @@ func dumpobj1(outfile string, mode int) { dumpLinkerObj(bout) finishArchiveEntry(bout, start, "_go_.o") } + + if err := bout.Close(); err != nil { + base.FlushErrors() + fmt.Printf("error while writing to file %s: %v\n", outfile, err) + base.ErrorExit() + } } func printObjHeader(bout *bio.Writer) {