1
0
mirror of https://github.com/json-iterator/go.git synced 2025-05-22 22:00:15 +02:00

fix read int

This commit is contained in:
Tao Wen 2017-02-07 09:24:36 +08:00
parent 6880076b44
commit 2922666717
4 changed files with 26 additions and 2 deletions

View File

@ -16,7 +16,7 @@ func Unmarshal(data []byte, v interface{}) error {
return nil
}
if iter.Error == nil {
iter.reportError("UnmarshalAny", "there are bytes left after unmarshal")
iter.reportError("Unmarshal", "there are bytes left after unmarshal")
}
return iter.Error
}

View File

@ -1,6 +1,8 @@
package jsoniter
import "strconv"
import (
"strconv"
)
var intDigits []int8
@ -124,6 +126,7 @@ func (iter *Iterator) readUint32(c byte) (ret uint32) {
for i := iter.head; i < iter.tail; i++ {
ind = intDigits[iter.buf[i]]
if ind == invalidCharForNumber {
iter.head = i
return value
}
if value > uint32SafeToMultiply10 {
@ -181,6 +184,7 @@ func (iter *Iterator) readUint64(c byte) (ret uint64) {
for i := iter.head; i < iter.tail; i++ {
ind = intDigits[iter.buf[i]]
if ind == invalidCharForNumber {
iter.head = i
return value
}
if value > uint64SafeToMultiple10 {

View File

@ -17,6 +17,10 @@ func NewStream(out io.Writer, bufSize int) *Stream {
return &Stream{out, make([]byte, bufSize), 0, nil, 0, 0}
}
func (b *Stream) Reset(out io.Writer) {
b.out = out
b.n = 0
}
// Available returns how many bytes are unused in the buffer.
func (b *Stream) Available() int {

View File

@ -64,6 +64,22 @@ func Test_read_int32(t *testing.T) {
}
}
func Test_read_int32_array(t *testing.T) {
should := require.New(t)
input := `[123,456,789]`
val := make([]int32, 0)
UnmarshalFromString(input, &val)
should.Equal(3, len(val))
}
func Test_read_int64_array(t *testing.T) {
should := require.New(t)
input := `[123,456,789]`
val := make([]int64, 0)
UnmarshalFromString(input, &val)
should.Equal(3, len(val))
}
func Test_read_int32_overflow(t *testing.T) {
should := require.New(t)
input := "123456789123456789,"