فهرست منبع

goprotobuf: Fix proto.Clone operating on empty-but-non-nil []byte values.

LGTM=djd
R=djd
CC=golang-codereviews
https://codereview.appspot.com/173410043
David Symonds 11 سال پیش
والد
کامیت
ceb17a4d1e
1فایلهای تغییر یافته به همراه3 افزوده شده و 1 حذف شده
  1. 3 1
      proto/clone.go

+ 3 - 1
proto/clone.go

@@ -128,7 +128,9 @@ func mergeAny(out, in reflect.Value) {
 		if in.Type().Elem().Kind() == reflect.Uint8 {
 			// []byte is a scalar bytes field, not a repeated field.
 			// Make a deep copy.
-			out.SetBytes(append([]byte(nil), in.Bytes()...))
+			// Append to []byte{} instead of []byte(nil) so that we never end up
+			// with a nil result.
+			out.SetBytes(append([]byte{}, in.Bytes()...))
 			return
 		}
 		n := in.Len()