Changeset View
Changeset View
Standalone View
Standalone View
contrib/ldns/radix.c
Show First 20 Lines • Show All 219 Lines • ▼ Show 20 Lines | if (len == 0) { | ||||
LDNS_FREE(prefix); | LDNS_FREE(prefix); | ||||
return LDNS_STATUS_MEM_ERR; | return LDNS_STATUS_MEM_ERR; | ||||
} | } | ||||
} | } | ||||
tree->root = prefix; | tree->root = prefix; | ||||
} | } | ||||
} else if (pos == len) { | } else if (pos == len) { | ||||
/** Exact match found */ | /** Exact match found */ | ||||
LDNS_FREE(add); | |||||
if (prefix->data) { | if (prefix->data) { | ||||
/* Element already exists */ | /* Element already exists */ | ||||
LDNS_FREE(add); | |||||
return LDNS_STATUS_EXISTS_ERR; | return LDNS_STATUS_EXISTS_ERR; | ||||
} | } | ||||
prefix->data = data; | prefix->data = data; | ||||
prefix->key = key; | prefix->key = key; | ||||
prefix->klen = len; /* redundant */ | prefix->klen = len; /* redundant */ | ||||
} else { | } else { | ||||
/** Prefix found */ | /** Prefix found */ | ||||
uint8_t byte = key[pos]; | uint8_t byte = key[pos]; | ||||
▲ Show 20 Lines • Show All 876 Lines • ▼ Show 20 Lines | if (ldns_radix_str_is_prefix(str_to_add, strlen_to_add, | ||||
/** Create the new common node. */ | /** Create the new common node. */ | ||||
common = ldns_radix_new_node(NULL, (uint8_t*)"", 0); | common = ldns_radix_new_node(NULL, (uint8_t*)"", 0); | ||||
if (!common) { | if (!common) { | ||||
return 0; | return 0; | ||||
} | } | ||||
if (array->len - common_len > 1) { | if (array->len - common_len > 1) { | ||||
if (!ldns_radix_prefix_remainder(common_len+1, | if (!ldns_radix_prefix_remainder(common_len+1, | ||||
array->str, array->len, &s1, &l1)) { | array->str, array->len, &s1, &l1)) { | ||||
LDNS_FREE(common); | |||||
return 0; | return 0; | ||||
} | } | ||||
} | } | ||||
if (strlen_to_add - common_len > 1) { | if (strlen_to_add - common_len > 1) { | ||||
if (!ldns_radix_prefix_remainder(common_len+1, | if (!ldns_radix_prefix_remainder(common_len+1, | ||||
str_to_add, strlen_to_add, &s2, &l2)) { | str_to_add, strlen_to_add, &s2, &l2)) { | ||||
LDNS_FREE(common); | |||||
LDNS_FREE(s1); | |||||
return 0; | return 0; | ||||
} | } | ||||
} | } | ||||
/** Create the shared prefix. */ | /** Create the shared prefix. */ | ||||
if (common_len > 0) { | if (common_len > 0) { | ||||
common_str = LDNS_XMALLOC(uint8_t, common_len); | common_str = LDNS_XMALLOC(uint8_t, common_len); | ||||
if (!common_str) { | if (!common_str) { | ||||
LDNS_FREE(common); | LDNS_FREE(common); | ||||
▲ Show 20 Lines • Show All 454 Lines • Show Last 20 Lines |