@@ -28,24 +28,19 @@ func (d *decoder) setError(namespace []byte, err error) {
2828 if d .errs == nil {
2929 d .errs = make (DecodeErrors )
3030 }
31-
3231 d .errs [string (namespace )] = err
3332}
3433
3534func (d * decoder ) findAlias (ns string ) * recursiveData {
36-
3735 for i := 0 ; i < len (d .dm ); i ++ {
38-
3936 if d .dm [i ].alias == ns {
4037 return d .dm [i ]
4138 }
4239 }
43-
4440 return nil
4541}
4642
4743func (d * decoder ) parseMapData () {
48-
4944 // already parsed
5045 if len (d .dm ) > 0 {
5146 return
@@ -153,7 +148,6 @@ func (d *decoder) traverseStruct(v reflect.Value, typ reflect.Type, namespace []
153148 }
154149
155150 for _ , f := range s .fields {
156-
157151 namespace = namespace [:l ]
158152
159153 if f .isAnonymous {
@@ -202,28 +196,27 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
202196 }
203197 switch kind {
204198 case reflect .Interface :
205- if ! ok {
199+ if ! ok || idx == len ( arr ) {
206200 return
207201 }
208202 v .Set (reflect .ValueOf (arr [idx ]))
209203 set = true
210204
211205 case reflect .Ptr :
212-
213206 newVal := reflect .New (v .Type ().Elem ())
214207 if set = d .setFieldByType (newVal .Elem (), namespace , idx ); set {
215208 v .Set (newVal )
216209 }
217210
218211 case reflect .String :
219- if ! ok {
212+ if ! ok || idx == len ( arr ) {
220213 return
221214 }
222215 v .SetString (arr [idx ])
223216 set = true
224217
225218 case reflect .Uint , reflect .Uint64 :
226- if ! ok || len (arr [idx ]) == 0 {
219+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
227220 return
228221 }
229222 var u64 uint64
@@ -235,7 +228,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
235228 set = true
236229
237230 case reflect .Uint8 :
238- if ! ok || len (arr [idx ]) == 0 {
231+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
239232 return
240233 }
241234 var u64 uint64
@@ -247,7 +240,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
247240 set = true
248241
249242 case reflect .Uint16 :
250- if ! ok || len (arr [idx ]) == 0 {
243+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
251244 return
252245 }
253246 var u64 uint64
@@ -259,7 +252,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
259252 set = true
260253
261254 case reflect .Uint32 :
262- if ! ok || len (arr [idx ]) == 0 {
255+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
263256 return
264257 }
265258 var u64 uint64
@@ -271,7 +264,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
271264 set = true
272265
273266 case reflect .Int , reflect .Int64 :
274- if ! ok || len (arr [idx ]) == 0 {
267+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
275268 return
276269 }
277270 var i64 int64
@@ -283,7 +276,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
283276 set = true
284277
285278 case reflect .Int8 :
286- if ! ok || len (arr [idx ]) == 0 {
279+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
287280 return
288281 }
289282 var i64 int64
@@ -295,7 +288,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
295288 set = true
296289
297290 case reflect .Int16 :
298- if ! ok || len (arr [idx ]) == 0 {
291+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
299292 return
300293 }
301294 var i64 int64
@@ -307,7 +300,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
307300 set = true
308301
309302 case reflect .Int32 :
310- if ! ok || len (arr [idx ]) == 0 {
303+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
311304 return
312305 }
313306 var i64 int64
@@ -319,7 +312,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
319312 set = true
320313
321314 case reflect .Float32 :
322- if ! ok || len (arr [idx ]) == 0 {
315+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
323316 return
324317 }
325318 var f float64
@@ -331,7 +324,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
331324 set = true
332325
333326 case reflect .Float64 :
334- if ! ok || len (arr [idx ]) == 0 {
327+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
335328 return
336329 }
337330 var f float64
@@ -343,7 +336,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
343336 set = true
344337
345338 case reflect .Bool :
346- if ! ok {
339+ if ! ok || idx == len ( arr ) {
347340 return
348341 }
349342 var b bool
0 commit comments