@@ -28,24 +28,19 @@ func (d *decoder) setError(namespace []byte, err error) {
28
28
if d .errs == nil {
29
29
d .errs = make (DecodeErrors )
30
30
}
31
-
32
31
d .errs [string (namespace )] = err
33
32
}
34
33
35
34
func (d * decoder ) findAlias (ns string ) * recursiveData {
36
-
37
35
for i := 0 ; i < len (d .dm ); i ++ {
38
-
39
36
if d .dm [i ].alias == ns {
40
37
return d .dm [i ]
41
38
}
42
39
}
43
-
44
40
return nil
45
41
}
46
42
47
43
func (d * decoder ) parseMapData () {
48
-
49
44
// already parsed
50
45
if len (d .dm ) > 0 {
51
46
return
@@ -153,7 +148,6 @@ func (d *decoder) traverseStruct(v reflect.Value, typ reflect.Type, namespace []
153
148
}
154
149
155
150
for _ , f := range s .fields {
156
-
157
151
namespace = namespace [:l ]
158
152
159
153
if f .isAnonymous {
@@ -202,28 +196,27 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
202
196
}
203
197
switch kind {
204
198
case reflect .Interface :
205
- if ! ok {
199
+ if ! ok || idx == len ( arr ) {
206
200
return
207
201
}
208
202
v .Set (reflect .ValueOf (arr [idx ]))
209
203
set = true
210
204
211
205
case reflect .Ptr :
212
-
213
206
newVal := reflect .New (v .Type ().Elem ())
214
207
if set = d .setFieldByType (newVal .Elem (), namespace , idx ); set {
215
208
v .Set (newVal )
216
209
}
217
210
218
211
case reflect .String :
219
- if ! ok {
212
+ if ! ok || idx == len ( arr ) {
220
213
return
221
214
}
222
215
v .SetString (arr [idx ])
223
216
set = true
224
217
225
218
case reflect .Uint , reflect .Uint64 :
226
- if ! ok || len (arr [idx ]) == 0 {
219
+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
227
220
return
228
221
}
229
222
var u64 uint64
@@ -235,7 +228,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
235
228
set = true
236
229
237
230
case reflect .Uint8 :
238
- if ! ok || len (arr [idx ]) == 0 {
231
+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
239
232
return
240
233
}
241
234
var u64 uint64
@@ -247,7 +240,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
247
240
set = true
248
241
249
242
case reflect .Uint16 :
250
- if ! ok || len (arr [idx ]) == 0 {
243
+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
251
244
return
252
245
}
253
246
var u64 uint64
@@ -259,7 +252,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
259
252
set = true
260
253
261
254
case reflect .Uint32 :
262
- if ! ok || len (arr [idx ]) == 0 {
255
+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
263
256
return
264
257
}
265
258
var u64 uint64
@@ -271,7 +264,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
271
264
set = true
272
265
273
266
case reflect .Int , reflect .Int64 :
274
- if ! ok || len (arr [idx ]) == 0 {
267
+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
275
268
return
276
269
}
277
270
var i64 int64
@@ -283,7 +276,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
283
276
set = true
284
277
285
278
case reflect .Int8 :
286
- if ! ok || len (arr [idx ]) == 0 {
279
+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
287
280
return
288
281
}
289
282
var i64 int64
@@ -295,7 +288,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
295
288
set = true
296
289
297
290
case reflect .Int16 :
298
- if ! ok || len (arr [idx ]) == 0 {
291
+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
299
292
return
300
293
}
301
294
var i64 int64
@@ -307,7 +300,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
307
300
set = true
308
301
309
302
case reflect .Int32 :
310
- if ! ok || len (arr [idx ]) == 0 {
303
+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
311
304
return
312
305
}
313
306
var i64 int64
@@ -319,7 +312,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
319
312
set = true
320
313
321
314
case reflect .Float32 :
322
- if ! ok || len (arr [idx ]) == 0 {
315
+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
323
316
return
324
317
}
325
318
var f float64
@@ -331,7 +324,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
331
324
set = true
332
325
333
326
case reflect .Float64 :
334
- if ! ok || len (arr [idx ]) == 0 {
327
+ if ! ok || idx == len ( arr ) || len (arr [idx ]) == 0 {
335
328
return
336
329
}
337
330
var f float64
@@ -343,7 +336,7 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
343
336
set = true
344
337
345
338
case reflect .Bool :
346
- if ! ok {
339
+ if ! ok || idx == len ( arr ) {
347
340
return
348
341
}
349
342
var b bool
0 commit comments