From 44ae4689306c580a0ecad51d005e14942b0b5d25 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Thu, 24 Dec 2020 23:14:58 +0900 Subject: [PATCH] Fix array decoder --- decode_array.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/decode_array.go b/decode_array.go index d9f6af1..9b6336f 100644 --- a/decode_array.go +++ b/decode_array.go @@ -102,11 +102,19 @@ func (d *arrayDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64 idx := 0 for { cursor++ - c, err := d.valueDecoder.decode(buf, cursor, unsafe.Pointer(uintptr(p)+uintptr(idx)*d.size)) - if err != nil { - return 0, err + if idx < d.alen { + c, err := d.valueDecoder.decode(buf, cursor, unsafe.Pointer(uintptr(p)+uintptr(idx)*d.size)) + if err != nil { + return 0, err + } + cursor = c + } else { + c, err := skipValue(buf, cursor) + if err != nil { + return 0, err + } + cursor = c } - cursor = c cursor = skipWhiteSpace(buf, cursor) switch buf[cursor] { case ']':