// The value underlying e must be the correct type for the next
// data item received.
func (dec *Decoder) Decode(e interface{}) os.Error {
+ // If e represents a value, the answer won't get back to the
+ // caller. Make sure it's a pointer.
+ if _, ok := reflect.Typeof(e).(*reflect.PtrType); !ok {
+ dec.state.err = os.ErrorString("gob: attempt to decode into a non-pointer");
+ return dec.state.err;
+ }
+
// Make sure we're single-threaded through here.
dec.mutex.Lock();
defer dec.mutex.Unlock();
"io";
"os";
"reflect";
+ "strings";
"testing";
)
}
func TestTypeToPtrPtrPtrPtrType(t *testing.T) {
- // Encode a *T, decode a T
type Type2 struct {
a ****float;
}
}
func TestSlice(t *testing.T) {
- // Encode a *T, decode a T
type Type3 struct {
a []string;
}
t.Error(err)
}
}
+
+func TestValueError(t *testing.T) {
+ // Encode a *T, decode a T
+ type Type4 struct {
+ a int;
+ }
+ t4p := Type4{3}; // note: not a pointer, unlike the other tests.
+ var t4 Type4;
+ if err := encAndDec(t4, t4p); err == nil || strings.Index(err.String(), "pointer") <= 0 {
+ t.Error("expected error; got none or got wrong one")
+ }
+}