Explorar o código

goprotobuf: Fix bug in packed slice decoding.

R=adg
CC=golang-dev
http://codereview.appspot.com/4629089
David Symonds %!s(int64=14) %!d(string=hai) anos
pai
achega
56eb29e5c4
Modificáronse 1 ficheiros con 3 adicións e 23 borrados
  1. 3 23
      proto/decode.go

+ 3 - 23
proto/decode.go

@@ -420,17 +420,6 @@ func initSlice(pslice unsafe.Pointer, base uintptr) {
 	sp.Cap = startSize
 	sp.Cap = startSize
 }
 }
 
 
-// Make *pslice have base address base, length 0, and capacity max(startSize, n).
-func initSlicen(pslice unsafe.Pointer, base uintptr, n int) {
-	if n < startSize {
-		n = startSize
-	}
-	sp := (*reflect.SliceHeader)(pslice)
-	sp.Data = base
-	sp.Len = 0
-	sp.Cap = n
-}
-
 // Individual type decoders
 // Individual type decoders
 // For each,
 // For each,
 //	u is the decoded value,
 //	u is the decoded value,
@@ -538,10 +527,7 @@ func (o *Buffer) dec_slice_packed_bool(p *Properties, base uintptr, sbase uintpt
 
 
 	y := *x
 	y := *x
 	if cap(y) == 0 {
 	if cap(y) == 0 {
-		// Packed fields are usually only encoded once,
-		// so this branch is almost always executed.
-		// The append in the loop below takes care of other cases.
-		initSlicen(unsafe.Pointer(x), sbase+p.scratch, nb)
+		initSlice(unsafe.Pointer(x), sbase+p.scratch)
 		y = *x
 		y = *x
 	}
 	}
 
 
@@ -587,10 +573,7 @@ func (o *Buffer) dec_slice_packed_int32(p *Properties, base uintptr, sbase uintp
 
 
 	y := *x
 	y := *x
 	if cap(y) == 0 {
 	if cap(y) == 0 {
-		// Packed fields are usually only encoded once,
-		// so this branch is almost always executed.
-		// The append in the loop below takes care of other cases.
-		initSlicen(unsafe.Pointer(x), sbase+p.scratch, nb)
+		initSlice(unsafe.Pointer(x), sbase+p.scratch)
 		y = *x
 		y = *x
 	}
 	}
 
 
@@ -637,10 +620,7 @@ func (o *Buffer) dec_slice_packed_int64(p *Properties, base uintptr, sbase uintp
 
 
 	y := *x
 	y := *x
 	if cap(y) == 0 {
 	if cap(y) == 0 {
-		// Packed fields are usually only encoded once,
-		// so this branch is almost always executed.
-		// The append in the loop below takes care of other cases.
-		initSlicen(unsafe.Pointer(x), sbase+p.scratch, nb)
+		initSlice(unsafe.Pointer(x), sbase+p.scratch)
 		y = *x
 		y = *x
 	}
 	}