aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/hex
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoding/hex')
-rw-r--r--src/encoding/hex/hex.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/encoding/hex/hex.go b/src/encoding/hex/hex.go
index 2768f1bac6..18e0c09ef3 100644
--- a/src/encoding/hex/hex.go
+++ b/src/encoding/hex/hex.go
@@ -94,12 +94,13 @@ func EncodeToString(src []byte) string {
// DecodeString returns the bytes represented by the hexadecimal string s.
func DecodeString(s string) ([]byte, error) {
src := []byte(s)
- dst := make([]byte, DecodedLen(len(src)))
- _, err := Decode(dst, src)
+ // We can use the source slice itself as the destination
+ // because the decode loop increments by one and then the 'seen' byte is not used anymore.
+ len, err := Decode(src, src)
if err != nil {
return nil, err
}
- return dst, nil
+ return src[:len], nil
}
// Dump returns a string that contains a hex dump of the given data. The format