Commit b7c73110 authored by Rob Pike's avatar Rob Pike

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

Fixes #1278.

R=rsc
CC=golang-dev
https://golang.org/cl/3434046
parent 062406bc
...@@ -473,7 +473,7 @@ func (enc *Encoder) encOpFor(rt reflect.Type) (encOp, int) { ...@@ -473,7 +473,7 @@ func (enc *Encoder) encOpFor(rt reflect.Type) (encOp, int) {
elemOp, indir := enc.encOpFor(t.Elem()) elemOp, indir := enc.encOpFor(t.Elem())
op = func(i *encInstr, state *encoderState, p unsafe.Pointer) { op = func(i *encInstr, state *encoderState, p unsafe.Pointer) {
slice := (*reflect.SliceHeader)(p) slice := (*reflect.SliceHeader)(p)
if slice.Len == 0 { if !state.sendZero && slice.Len == 0 {
return return
} }
state.update(i) state.update(i)
...@@ -495,7 +495,7 @@ func (enc *Encoder) encOpFor(rt reflect.Type) (encOp, int) { ...@@ -495,7 +495,7 @@ func (enc *Encoder) encOpFor(rt reflect.Type) (encOp, int) {
// the iteration. // the iteration.
v := reflect.NewValue(unsafe.Unreflect(t, unsafe.Pointer((p)))) v := reflect.NewValue(unsafe.Unreflect(t, unsafe.Pointer((p))))
mv := reflect.Indirect(v).(*reflect.MapValue) mv := reflect.Indirect(v).(*reflect.MapValue)
if mv.Len() == 0 { if !state.sendZero && mv.Len() == 0 {
return return
} }
state.update(i) state.update(i)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment