mirror of https://github.com/goccy/go-json.git
Merge pull request #344 from orisano/fix/#343
fix: to care ints minimum values
This commit is contained in:
commit
e99e62dcbc
|
@ -1317,6 +1317,12 @@ var unmarshalTests = []unmarshalTest{
|
|||
ptr: new(string),
|
||||
out: "hello\ufffd\ufffd\ufffd\ufffd\ufffd\ufffdworld",
|
||||
},
|
||||
{in: "-128", ptr: new(int8), out: int8(-128)},
|
||||
{in: "127", ptr: new(int8), out: int8(127)},
|
||||
{in: "-32768", ptr: new(int16), out: int16(-32768)},
|
||||
{in: "32767", ptr: new(int16), out: int16(32767)},
|
||||
{in: "-2147483648", ptr: new(int32), out: int32(-2147483648)},
|
||||
{in: "2147483647", ptr: new(int32), out: int32(2147483647)},
|
||||
}
|
||||
|
||||
type All struct {
|
||||
|
|
|
@ -192,15 +192,15 @@ func (d *intDecoder) DecodeStream(s *Stream, depth int64, p unsafe.Pointer) erro
|
|||
}
|
||||
switch d.kind {
|
||||
case reflect.Int8:
|
||||
if i64 <= -1*(1<<7) || (1<<7) <= i64 {
|
||||
if i64 < -1*(1<<7) || (1<<7) <= i64 {
|
||||
return d.typeError(bytes, s.totalOffset())
|
||||
}
|
||||
case reflect.Int16:
|
||||
if i64 <= -1*(1<<15) || (1<<15) <= i64 {
|
||||
if i64 < -1*(1<<15) || (1<<15) <= i64 {
|
||||
return d.typeError(bytes, s.totalOffset())
|
||||
}
|
||||
case reflect.Int32:
|
||||
if i64 <= -1*(1<<31) || (1<<31) <= i64 {
|
||||
if i64 < -1*(1<<31) || (1<<31) <= i64 {
|
||||
return d.typeError(bytes, s.totalOffset())
|
||||
}
|
||||
}
|
||||
|
@ -225,15 +225,15 @@ func (d *intDecoder) Decode(ctx *RuntimeContext, cursor, depth int64, p unsafe.P
|
|||
}
|
||||
switch d.kind {
|
||||
case reflect.Int8:
|
||||
if i64 <= -1*(1<<7) || (1<<7) <= i64 {
|
||||
if i64 < -1*(1<<7) || (1<<7) <= i64 {
|
||||
return 0, d.typeError(bytes, cursor)
|
||||
}
|
||||
case reflect.Int16:
|
||||
if i64 <= -1*(1<<15) || (1<<15) <= i64 {
|
||||
if i64 < -1*(1<<15) || (1<<15) <= i64 {
|
||||
return 0, d.typeError(bytes, cursor)
|
||||
}
|
||||
case reflect.Int32:
|
||||
if i64 <= -1*(1<<31) || (1<<31) <= i64 {
|
||||
if i64 < -1*(1<<31) || (1<<31) <= i64 {
|
||||
return 0, d.typeError(bytes, cursor)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue