浏览代码

dns/dnsmessage: correct error message to be readable

My earlier change CL 220798 avoided a vet warning for string(i),
but neglected to consider that the vet warning was accurate:
the code was wrong.  The code assumed that string(rune(i)) would
return a readable version of i, but of course it instead returns
the UTF-8 encoding of i.

Updates golang/go#32479

Change-Id: I7410bf9fcd98cbdd193344118ecc81e967a6fb45
Reviewed-on: https://go-review.googlesource.com/c/net/+/221437
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Ian Lance Taylor 5 年之前
父节点
当前提交
244492dfa3
共有 1 个文件被更改,包括 2 次插入1 次删除
  1. 2 1
      dns/dnsmessage/message.go

+ 2 - 1
dns/dnsmessage/message.go

@@ -14,6 +14,7 @@ package dnsmessage
 
 import (
 	"errors"
+	"fmt"
 )
 
 // Message formats
@@ -2140,7 +2141,7 @@ func unpackResourceBody(msg []byte, off int, hdr ResourceHeader) (ResourceBody,
 		return nil, off, &nestedError{name + " record", err}
 	}
 	if r == nil {
-		return nil, off, errors.New("invalid resource type: " + string(rune(hdr.Type)+'0'))
+		return nil, off, fmt.Errorf("invalid resource type: %d", hdr.Type)
 	}
 	return r, off + int(hdr.Length), nil
 }