1
0
mirror of https://github.com/golang/go synced 2024-11-26 07:27:59 -07:00

cmd/internal/archive: make error message contain printable characters only

Use %q instead of %s to print unchecked bytes. Also strip the
"\x00" byte, as "go116ld" reads better than "\x00go116ld".

Change-Id: Id3d1f426ea91d53a55b928dac4a68e1333b80158
Reviewed-on: https://go-review.googlesource.com/c/go/+/315750
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
Cherry Zhang 2021-04-30 13:57:12 -04:00
parent c3b2b04156
commit 83ac59b1a5

View File

@ -109,7 +109,7 @@ var (
type ErrGoObjOtherVersion struct{ magic []byte }
func (e ErrGoObjOtherVersion) Error() string {
return fmt.Sprintf("go object of a different version: %s", e.magic)
return fmt.Sprintf("go object of a different version: %q", e.magic)
}
// An objReader is an object file reader.
@ -425,7 +425,7 @@ func (r *objReader) parseObject(o *GoObj, size int64) error {
}
if !bytes.Equal(p, []byte(goobj.Magic)) {
if bytes.HasPrefix(p, []byte("\x00go1")) && bytes.HasSuffix(p, []byte("ld")) {
return r.error(ErrGoObjOtherVersion{p})
return r.error(ErrGoObjOtherVersion{p[1:]}) // strip the \x00 byte
}
return r.error(errCorruptObject)
}