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) {
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)
......
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