Skip to content

Commit

Permalink
Initialise more boxes correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Sep 5, 2023
1 parent 8726e54 commit dc0c04c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/lib/util/dict_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, },
}
},
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/util/dict_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/lib/util/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 13 additions & 3 deletions src/lib/util/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down

0 comments on commit dc0c04c

Please sign in to comment.