Skip to content

Commit

Permalink
Make sure _fr_dbuff_init() returns a parentless dbuff (#3422)
Browse files Browse the repository at this point in the history
This also adds a test for that property.
  • Loading branch information
jejones3141 committed May 5, 2020
1 parent 7b25dd1 commit 0bc34ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/util/dbuff.h
Expand Up @@ -123,6 +123,7 @@ static inline void _fr_dbuff_init(fr_dbuff_t *out, uint8_t const *start, uint8_t
out->p_i = out->start_i = start;
out->end_i = end;
out->is_const = is_const;
out->parent = NULL;
}

/** Initialise an dbuff for encoding or decoding
Expand Down
11 changes: 11 additions & 0 deletions src/lib/util/dbuff_tests.c
Expand Up @@ -32,11 +32,22 @@ static void test_dbuff_init(void)
TEST_CHECK(dbuff.end == in + sizeof(in));
}

static void test_dbuff_init_no_parent(void)
{ uint8_t const in[] = { 0x01, 0x02, 0x03, 0x04 };
fr_dbuff_t dbuff;

TEST_CASE("Confirm init returns parentless dbuff");
fr_dbuff_init(&dbuff, in, sizeof(in));

TEST_CHECK(dbuff.parent == NULL);
}

TEST_LIST = {
/*
* Basic tests
*/
{ "fr_dbuff_init", test_dbuff_init },
{ "fr_dbuff_init_no_parent", test_dbuff_init_no_parent },

{ NULL }
};
Expand Down

0 comments on commit 0bc34ad

Please sign in to comment.