1
0
mirror of https://github.com/json-iterator/go.git synced 2025-01-08 13:06:29 +02:00

fix reuse buffer bug

This commit is contained in:
Tao Wen 2016-12-08 19:22:24 +08:00
parent d720b761fb
commit a460807cb4
2 changed files with 26 additions and 1 deletions

View File

@ -554,7 +554,27 @@ func (iter *Iterator) readObjectField() (ret string) {
iter.ReportError("ReadObject", "expect : after object field")
return
}
iter.skipWhitespaces()
// skip whitespaces, and detect if buffer is rotated
for {
for i := iter.head; i < iter.tail; i++ {
c := iter.buf[i]
switch c {
case ' ', '\n', '\t', '\r':
continue
}
iter.head = i
break
}
if iter.head == iter.tail {
// no longer safe to reuse buffer
field = string(str)
if !iter.loadMore() {
return
}
} else {
break
}
}
return field
}

File diff suppressed because one or more lines are too long