From dc0c04c5998163f38d0415734068b60ed4b8d579 Mon Sep 17 00:00:00 2001 From: Arran Cudbard-Bell Date: Tue, 5 Sep 2023 15:19:12 -0600 Subject: [PATCH] Initialise more boxes correctly --- src/lib/util/dict_test.c | 9 ++++++--- src/lib/util/dict_test.h | 2 +- src/lib/util/edit.c | 1 + src/lib/util/value.h | 16 +++++++++++++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/lib/util/dict_test.c b/src/lib/util/dict_test.c index 05fa379721bcb..dc670bba69344 100644 --- a/src/lib/util/dict_test.c +++ b/src/lib/util/dict_test.c @@ -80,6 +80,9 @@ fr_dict_attr_t const *fr_dict_attr_test_nested_leaf_int32; fr_dict_attr_t const *fr_dict_attr_test_enum; +static fr_value_box_t enum_test_0 = FR_VALUE_BOX_INITIALISER(enum_test_0, FR_TYPE_UINT32, .uint32, 123); +static fr_value_box_t enum_test_1 = FR_VALUE_BOX_INITIALISER(enum_test_1, FR_TYPE_UINT32, .uint32, 321); + fr_dict_test_attr_t const fr_dict_test_attrs[] = { /* * Variable length @@ -149,8 +152,8 @@ fr_dict_test_attr_t const fr_dict_test_attrs[] = { */ { .attr = FR_TEST_ATTR_ENUM, .da = &fr_dict_attr_test_enum, .name = "Test-Enum", .type = FR_TYPE_UINT32, .values = (fr_dict_test_attr_value_t[]){ - { .key = "test123", .val = { .type = FR_TYPE_UINT32, .vb_uint32 = 123 } }, - { .key = "test321", .val = { .type = FR_TYPE_UINT32, .vb_uint32 = 321 } }, + { .key = "test123", .val = &enum_test_0}, + { .key = "test321", .val = &enum_test_1}, { .key = NULL, }, } }, @@ -222,7 +225,7 @@ int fr_dict_test_attrs_init(fr_dict_t *dict, fr_dict_test_attr_t const *test_def for (v = p->values; v->key != NULL; - v++) fr_dict_enum_add_name(fr_dict_attr_unconst(attr), v->key, &v->val, false, false); + v++) fr_dict_enum_add_name(fr_dict_attr_unconst(attr), v->key, v->val, false, false); } *p->da = attr; diff --git a/src/lib/util/dict_test.h b/src/lib/util/dict_test.h index 8d90361f18f4a..3e8911bac7012 100644 --- a/src/lib/util/dict_test.h +++ b/src/lib/util/dict_test.h @@ -91,7 +91,7 @@ typedef enum { */ typedef struct value { char const *key; //!< Enumeration name. - fr_value_box_t val; //!< Enumeration value + fr_value_box_t *val; //!< Enumeration value } fr_dict_test_attr_value_t; /** Test enumeration attributes diff --git a/src/lib/util/edit.c b/src/lib/util/edit.c index eb77d456e547e..e147080656be7 100644 --- a/src/lib/util/edit.c +++ b/src/lib/util/edit.c @@ -460,6 +460,7 @@ static int edit_record(fr_edit_list_t *el, fr_edit_op_t op, fr_pair_t *vp, fr_pa e->op = op; e->vp = vp; + fr_value_box_init_null(&e->data); switch (op) { case FR_EDIT_INVALID: diff --git a/src/lib/util/value.h b/src/lib/util/value.h index 4ee74a2e37116..5059947b6aa2b 100644 --- a/src/lib/util/value.h +++ b/src/lib/util/value.h @@ -471,10 +471,20 @@ extern fr_sbuff_parse_rules_t const *value_parse_rules_quoted_char[UINT8_MAX]; #define FR_VALUE_BOX_INITIALISER_NULL(_vb) \ { \ .type = FR_TYPE_NULL, \ + .entry = { \ + .entry = FR_DLIST_ENTRY_INITIALISER((_vb).entry.entry) \ + }, \ + VALUE_BOX_NDEBUG_INITIALISER \ + } + +/** A static initialiser for stack/globally allocated boxes + * + */ +#define FR_VALUE_BOX_INITIALISER(_vb, _type, _field, _val) \ + { \ + .type = _type, \ .datum = { \ - .children = { \ - FR_DLIST_HEAD_INITIALISER((_vb).datum.children.head) \ - } \ + _field = _val, \ }, \ .entry = { \ .entry = FR_DLIST_ENTRY_INITIALISER((_vb).entry.entry) \