encoding/json: Fix panic when trying to unmarshal the empty string into an integer

Fixes #3450.

R=rsc, bradfitz
CC=golang-dev
https://golang.org/cl/6035050
This commit is contained in:
Michael Chaten 2012-05-03 17:35:44 -04:00 committed by Russ Cox
parent 61060acdc1
commit 3fab2a97e4
2 changed files with 24 additions and 0 deletions

View file

@ -593,6 +593,11 @@ func (d *decodeState) literal(v reflect.Value) {
// produce more helpful error messages.
func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool) {
// Check for unmarshaler.
if len(item) == 0 {
//Empty string given
d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type()))
return
}
wantptr := item[0] == 'n' // null
unmarshaler, pv := d.indirect(v, wantptr)
if unmarshaler != nil {