Make it a runtime error to try and unmarshal into a value.
Thanks to Rob Pike for the suggestion and code.
This commit is contained in:
parent
0804ed1920
commit
f980a9f931
2 changed files with 7 additions and 1 deletions
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// Represents JSON data structure using native Go types: booleans, floats,
|
// Represents bencode data structure using native Go types: booleans, floats,
|
||||||
// strings, arrays, and maps.
|
// strings, arrays, and maps.
|
||||||
|
|
||||||
package bencode
|
package bencode
|
||||||
|
|
|
@ -279,6 +279,12 @@ func (b *structBuilder) Key(k string) Builder {
|
||||||
//
|
//
|
||||||
|
|
||||||
func Unmarshal(r io.Reader, val interface{}) (err os.Error) {
|
func Unmarshal(r io.Reader, val interface{}) (err 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(val).(*reflect.PtrType); !ok {
|
||||||
|
err = os.ErrorString("Attempt to unmarshal into a non-pointer")
|
||||||
|
return
|
||||||
|
}
|
||||||
err = UnmarshalValue(r, reflect.NewValue(val))
|
err = UnmarshalValue(r, reflect.NewValue(val))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue