From a4166acb601d46d9158c2762b415f843c1bdf83c Mon Sep 17 00:00:00 2001 From: smasher164 Date: Thu, 27 Feb 2020 14:42:00 -0500 Subject: [PATCH] profile: change error message to print string representation of wire type The proto write type code stored in buffer stores unprintable values (e.g. 2 when unmarshalling). The desired output when printing an error message is the string representation of the integer (i.e. strconv.Itoa), instead of the current behavior string(int) or string(rune), which return the utf8 literal corresponding to the integer. As pointed out by @ianlancetaylor in https://github.com/google/pprof/commit/4ac0da8#commitcomment-37524728, commit 4ac0da8 preserves the previous incorrect behavior to pass a vet check, whereas this change prints the desired output. Updates golang/go#32479. --- profile/proto.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/profile/proto.go b/profile/proto.go index 5c67c60126..539ad3ab33 100644 --- a/profile/proto.go +++ b/profile/proto.go @@ -33,7 +33,10 @@ package profile -import "errors" +import ( + "errors" + "fmt" +) type buffer struct { field int // field tag @@ -235,7 +238,7 @@ func decodeField(b *buffer, data []byte) ([]byte, error) { b.u64 = uint64(le32(data[:4])) data = data[4:] default: - return nil, errors.New("unknown wire type: " + string(rune(b.typ))) + return nil, fmt.Errorf("unknown wire type: %d", b.typ) } return data, nil