]> Cypherpunks repositories - gostls13.git/commitdiff
Fix a proto encoding crasher whereby a nil in a repeated group field would crash...
authorDavid Symonds <dsymonds@golang.org>
Tue, 16 Jun 2009 01:35:04 +0000 (18:35 -0700)
committerDavid Symonds <dsymonds@golang.org>
Tue, 16 Jun 2009 01:35:04 +0000 (18:35 -0700)
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

src/pkg/reflect/all_test.go
src/pkg/reflect/deepequal.go
src/pkg/reflect/value.go

index 903b0f5260d209fce7b4c16afd50712c65e06c25..987acd48e565ba88941fa87d73740785000941fb 100644 (file)
@@ -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");
+       }
+}
index 57b52485f7b42dde6a2d697353f9d0b1f925f5d3..5c3cd4a8258e1ff3062c9c77a550a8e2e5b59dc9 100644 (file)
@@ -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;
        }
index d4783d54675a0447979ca962f1f66c998f5c1e52..5c39583829e89724591693f0a7f6e5d5fc89c006 100644 (file)
@@ -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} };
 }