mirror of https://github.com/golang/go.git
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
This commit is contained in:
parent
a893db8767
commit
d4e57ff248
|
|
@ -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} };
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue