]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Initialise more boxes correctly
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 5 Sep 2023 21:19:12 +0000 (15:19 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 5 Sep 2023 21:20:13 +0000 (15:20 -0600)
src/lib/util/dict_test.c
src/lib/util/dict_test.h
src/lib/util/edit.c
src/lib/util/value.h

index 05fa379721bcbe46b684e73e93be275c7bd6a304..dc670bba693442d13932d6e1ca4199b8600da61f 100644 (file)
@@ -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;
index 8d90361f18f4a203cd24c9cf9bf0482a5b7884f5..3e8911bac7012b243446b00d5eacabddaa3ab110 100644 (file)
@@ -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
index eb77d456e547ed3b9ecb62b970dda91cf5394aca..e147080656be72e2e4530a41499510c739ff71b6 100644 (file)
@@ -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:
index 4ee74a2e371169a12bafba8619d66f2a8be032df..5059947b6aa2b41a2de8cd197b3457bc39d0e346 100644 (file)
@@ -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) \