|
@@ -76,7 +76,9 @@ void dtrie_delete(struct dtrie_node_t *root, struct dtrie_node_t *node,
|
|
dt_delete_func_t delete_payload, const unsigned int branches)
|
|
dt_delete_func_t delete_payload, const unsigned int branches)
|
|
{
|
|
{
|
|
unsigned int i;
|
|
unsigned int i;
|
|
- if (node==NULL) return;
|
|
|
|
|
|
+
|
|
|
|
+ if (node == NULL) return;
|
|
|
|
+ if (root == NULL) return;
|
|
|
|
|
|
for (i=0; i<branches; i++) {
|
|
for (i=0; i<branches; i++) {
|
|
dtrie_delete(root, node->child[i], delete_payload, branches);
|
|
dtrie_delete(root, node->child[i], delete_payload, branches);
|
|
@@ -123,6 +125,10 @@ int dtrie_insert(struct dtrie_node_t *root, const char *number, const unsigned i
|
|
struct dtrie_node_t *node = root;
|
|
struct dtrie_node_t *node = root;
|
|
unsigned char digit, i=0;
|
|
unsigned char digit, i=0;
|
|
|
|
|
|
|
|
+ if (node == NULL) return -1;
|
|
|
|
+ if (root == NULL) return -1;
|
|
|
|
+ if (number == NULL) return -1;
|
|
|
|
+
|
|
while (i<numberlen) {
|
|
while (i<numberlen) {
|
|
if (branches==10) {
|
|
if (branches==10) {
|
|
digit = number[i] - '0';
|
|
digit = number[i] - '0';
|
|
@@ -202,6 +208,8 @@ unsigned int dtrie_leaves(const struct dtrie_node_t *root, const unsigned int br
|
|
{
|
|
{
|
|
unsigned int i, sum = 0, leaf = 1;
|
|
unsigned int i, sum = 0, leaf = 1;
|
|
|
|
|
|
|
|
+ if (root == NULL) return 0;
|
|
|
|
+
|
|
for (i=0; i<branches; i++) {
|
|
for (i=0; i<branches; i++) {
|
|
if (root->child[i]) {
|
|
if (root->child[i]) {
|
|
sum += dtrie_leaves(root->child[i], branches);
|
|
sum += dtrie_leaves(root->child[i], branches);
|
|
@@ -220,6 +228,10 @@ void **dtrie_longest_match(struct dtrie_node_t *root, const char *number,
|
|
unsigned char digit, i = 0;
|
|
unsigned char digit, i = 0;
|
|
void **ret = NULL;
|
|
void **ret = NULL;
|
|
|
|
|
|
|
|
+ if (node == NULL) return NULL;
|
|
|
|
+ if (root == NULL) return NULL;
|
|
|
|
+ if (number == NULL) return NULL;
|
|
|
|
+
|
|
if (nmatchptr) *nmatchptr=-1;
|
|
if (nmatchptr) *nmatchptr=-1;
|
|
if (node->data != NULL) {
|
|
if (node->data != NULL) {
|
|
if (nmatchptr) *nmatchptr=0;
|
|
if (nmatchptr) *nmatchptr=0;
|