1
0
mirror of https://github.com/golang/go synced 2024-11-21 18:14:42 -07:00

gob: fix bug sending zero-length top-level slices and maps

Fixes #1278.

R=rsc
CC=golang-dev
https://golang.org/cl/3434046
This commit is contained in:
Rob Pike 2010-12-09 11:01:32 -05:00
parent 062406bc64
commit b7c73110b1

View File

@ -473,7 +473,7 @@ func (enc *Encoder) encOpFor(rt reflect.Type) (encOp, int) {
elemOp, indir := enc.encOpFor(t.Elem())
op = func(i *encInstr, state *encoderState, p unsafe.Pointer) {
slice := (*reflect.SliceHeader)(p)
if slice.Len == 0 {
if !state.sendZero && slice.Len == 0 {
return
}
state.update(i)
@ -495,7 +495,7 @@ func (enc *Encoder) encOpFor(rt reflect.Type) (encOp, int) {
// the iteration.
v := reflect.NewValue(unsafe.Unreflect(t, unsafe.Pointer((p))))
mv := reflect.Indirect(v).(*reflect.MapValue)
if mv.Len() == 0 {
if !state.sendZero && mv.Len() == 0 {
return
}
state.update(i)