2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 14:07:59 +00:00

Refactor isc_radix_create to return void

The isc_radix_create() can't fail, so change it to return void.
This commit is contained in:
Ondřej Surý 2023-10-13 08:03:06 +02:00 committed by Ondřej Surý
parent b54498abf6
commit d46d51be78
4 changed files with 13 additions and 29 deletions

View File

@ -28,7 +28,6 @@ destroy_iptable(dns_iptable_t *dtab);
*/
isc_result_t
dns_iptable_create(isc_mem_t *mctx, dns_iptable_t **target) {
isc_result_t result;
dns_iptable_t *tab;
tab = isc_mem_get(mctx, sizeof(*tab));
@ -38,17 +37,10 @@ dns_iptable_create(isc_mem_t *mctx, dns_iptable_t **target) {
tab->radix = NULL;
tab->magic = DNS_IPTABLE_MAGIC;
result = isc_radix_create(mctx, &tab->radix, RADIX_MAXBITS);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
isc_radix_create(mctx, &tab->radix, RADIX_MAXBITS);
*target = tab;
return (ISC_R_SUCCESS);
cleanup:
dns_iptable_detach(&tab);
return (result);
}
static bool dns_iptable_neg = false;

View File

@ -100,8 +100,8 @@ typedef struct isc_radix_node {
* nodes */
} isc_radix_node_t;
#define RADIX_TREE_MAGIC ISC_MAGIC('R', 'd', 'x', 'T');
#define RADIX_TREE_VALID(a) ISC_MAGIC_VALID(a, RADIX_TREE_MAGIC);
#define RADIX_TREE_MAGIC ISC_MAGIC('R', 'd', 'x', 'T')
#define RADIX_TREE_VALID(a) ISC_MAGIC_VALID(a, RADIX_TREE_MAGIC)
typedef struct isc_radix_tree {
unsigned int magic;
@ -157,7 +157,7 @@ isc_radix_remove(isc_radix_tree_t *radix, isc_radix_node_t *node);
* \li 'node' to be valid.
*/
isc_result_t
void
isc_radix_create(isc_mem_t *mctx, isc_radix_tree_t **target, int maxbits);
/*%<
* Create a radix tree with a maximum depth of 'maxbits';

View File

@ -131,24 +131,18 @@ _comp_with_mask(void *addr, void *dest, u_int mask) {
return (0);
}
isc_result_t
void
isc_radix_create(isc_mem_t *mctx, isc_radix_tree_t **target, int maxbits) {
isc_radix_tree_t *radix;
REQUIRE(target != NULL && *target == NULL);
RUNTIME_CHECK(maxbits <= RADIX_MAXBITS);
radix = isc_mem_get(mctx, sizeof(isc_radix_tree_t));
radix->mctx = NULL;
isc_radix_tree_t *radix = isc_mem_get(mctx, sizeof(isc_radix_tree_t));
*radix = (isc_radix_tree_t){
.maxbits = maxbits,
.magic = RADIX_TREE_MAGIC,
};
isc_mem_attach(mctx, &radix->mctx);
radix->maxbits = maxbits;
radix->head = NULL;
radix->num_active_node = 0;
radix->num_added_node = 0;
RUNTIME_CHECK(maxbits <= RADIX_MAXBITS); /* XXX */
radix->magic = RADIX_TREE_MAGIC;
*target = radix;
return (ISC_R_SUCCESS);
}
/*

View File

@ -41,8 +41,7 @@ ISC_RUN_TEST_IMPL(isc_radix_remove) {
UNUSED(state);
result = isc_radix_create(mctx, &radix, 32);
assert_int_equal(result, ISC_R_SUCCESS);
isc_radix_create(mctx, &radix, 32);
in_addr.s_addr = inet_addr("1.1.1.1");
isc_netaddr_fromin(&netaddr, &in_addr);
@ -90,8 +89,7 @@ ISC_RUN_TEST_IMPL(isc_radix_search) {
UNUSED(state);
result = isc_radix_create(mctx, &radix, 32);
assert_int_equal(result, ISC_R_SUCCESS);
isc_radix_create(mctx, &radix, 32);
in_addr.s_addr = inet_addr("3.3.3.0");
isc_netaddr_fromin(&netaddr, &in_addr);