]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: handle errors from *bio.Writer
authorMateusz Poliwczak <mpoliwczak34@gmail.com>
Sat, 8 Feb 2025 13:59:18 +0000 (13:59 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 10 Feb 2025 21:08:23 +0000 (13:08 -0800)
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 <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Keith Randall <khr@golang.org>

src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/gc/obj.go

index c93f008ba2c26bf6e9277acf48b2c411daea7e58..9afbeb9d3b5c9197bdad042ccbde1c32b0c6f59d 100644 (file)
@@ -47,5 +47,7 @@ func dumpasmhdr() {
                }
        }
 
-       b.Close()
+       if err := b.Close(); err != nil {
+               base.Fatalf("%v", err)
+       }
 }
index 4b42c81ef8184523087f3e392716f48f23b3621d..37bbce03189c24294e164a947901966648ad2962 100644 (file)
@@ -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("!<arch>\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) {