purpleidea / mgmt

Next generation distributed, event-driven, parallel config management!
https://purpleidea.com/tags/mgmtconfig/
GNU General Public License v3.0
3.67k stars 315 forks source link

lang: Fix panic in lang/types/ValueOf() for Struct #627

Closed frebib closed 3 years ago

frebib commented 3 years ago

Replace use of reflect.Value.Len() with NumField() which is intended to return the number of fields in reflected Struct value.

Len should only be used for Array, Chan, Map, Slice and String types.

Add some trivial sanity check tests for ValueOf() for the simple and complex container types.

Signed-off-by: Joe Groocock me@frebib.net

purpleidea commented 3 years ago

This looks perfect, and a nice catch too! Thank you =D

purpleidea commented 3 years ago

Woops. I didn't merge this, because it fails tests. One sec, I'll post output

purpleidea commented 3 years ago

Merged in https://github.com/purpleidea/mgmt/commit/845d7ff188480737070c19a6178502e517746120 \o/