ffjson icon indicating copy to clipboard operation
ffjson copied to clipboard

nil pointer dereference when unmarshalling time.Time to pointer

Open driesdev opened this issue 4 years ago • 0 comments

the generated code is

			var tmpJSpecialDates *time.Time

			tok = fs.Scan()
			if tok == fflib.FFTok_error {
				goto tokerror
			}
			if tok == fflib.FFTok_right_brace {
				break
			}

			if tok == fflib.FFTok_comma {
				if wantVal == true {
					// TODO(pquerna): this isn't an ideal error message, this handles
					// things like [,,,] as an array value.
					return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
				}
				continue
			} else {
				wantVal = true
			}

			/* handler: tmpJSpecialDates type=*time.Time kind=ptr quoted=false*/

			{
				if tok == fflib.FFTok_null {

				} else {

					tbuf, err := fs.CaptureField(tok)
					if err != nil {
						return fs.WrapErr(err)
					}

					err = tmpJSpecialDates.UnmarshalJSON(tbuf)
					if err != nil {
						return fs.WrapErr(err)
					}
				}
				state = fflib.FFParse_after_value
			}

tmpJSpecialDates here never gets assigned a value, hence when UnmarshalJSON is called on it, it causes a panic.

driesdev avatar Nov 21 '19 13:11 driesdev