Commit d4e57ff2 authored by David Symonds's avatar David Symonds

Fix a proto encoding crasher whereby a nil in a repeated group field would crash the server.

Also fix the reflect bug that was exposed by this bug.

R=r
APPROVED=rsc
DELTA=162  (103 added, 32 deleted, 27 changed)
OCL=30125
CL=30319
parent a893db87
......@@ -611,3 +611,10 @@ func TestInterfaceEditing(t *testing.T) {
t.Errorf("Set(234) changed i to %d", i.(int));
}
}
func TestNilPtrValueSub(t *testing.T) {
var pi *int;
if pv := NewValue(pi).(PtrValue); pv.Sub() != nil {
t.Error("NewValue((*int)(nil)).(PtrValue).Sub() != nil");
}
}
......@@ -12,6 +12,12 @@ import "reflect"
// comparisons that have already been seen, which allows short circuiting on
// recursive types.
func deepValueEqual(v1, v2 Value, visited map[Addr]Addr) bool {
if v1 == nil {
return v2 == nil
}
if v2 == nil {
return false
}
if v1.Kind() != v2.Kind() {
return false;
}
......
......@@ -512,7 +512,14 @@ func (v *ptrValueStruct) Get() Addr {
return *(*Addr)(v.addr)
}
func (v *ptrValueStruct) IsNil() bool {
return uintptr(*(*Addr)(v.addr)) == 0
}
func (v *ptrValueStruct) Sub() Value {
if v.IsNil() {
return nil
}
return newValueAddr(v.typ.(PtrType).Sub(), v.Get());
}
......@@ -526,10 +533,6 @@ func (v *ptrValueStruct) SetSub(subv Value) {
*(*Addr)(v.addr) = subv.Addr();
}
func (v *ptrValueStruct) IsNil() bool {
return uintptr(*(*Addr)(v.addr)) == 0
}
func ptrCreator(typ Type, addr Addr) Value {
return &ptrValueStruct{ commonValue{PtrKind, typ, addr} };
}
......
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