From ecdac2515d74ac7a4a03691a3661efbc282c32e0 Mon Sep 17 00:00:00 2001 From: Jan Kadlec <jan@hp4-jankadlec.(none)> Date: Wed, 24 Nov 2010 10:58:30 +0100 Subject: [PATCH] Changed node implementation. Previously, keys of skip list, although defined as null pointers, contained actual key (type of RRset, that is), which did not comply with definitions, and therefore was producing warnings. Changed node test, so that they reflect this fact. Skip list's function return_list() and list_length() now obsolete. Refs #121 --- src/dnslib/node.c | 7 ++++--- src/tests/dnslib/dnslib_node_tests.c | 19 +++++++------------ src/tests/dnslib/dnslib_rrset_tests.c | 7 +++---- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/dnslib/node.c b/src/dnslib/node.c index 971fa267e..6fb19b6dc 100644 --- a/src/dnslib/node.c +++ b/src/dnslib/node.c @@ -22,7 +22,8 @@ int compare_rrset_types( void *key1, void *key2 ) { - return (key1 == key2 ? 0 : key1 < key2 ? -1 : 1); + return (*((uint8_t *)key1) == *((uint8_t *)key2) ? + 0 : *((uint8_t *)key1) < *((uint8_t *)key2) ? -1 : 1); } dnslib_node_t *dnslib_node_new( dnslib_dname_t *owner, dnslib_node_t *parent ) @@ -42,7 +43,7 @@ dnslib_node_t *dnslib_node_new( dnslib_dname_t *owner, dnslib_node_t *parent ) int dnslib_node_add_rrset( dnslib_node_t *node, dnslib_rrset_t *rrset ) { - if ((skip_insert(node->rrsets, (void *)rrset->type, (void *)rrset, NULL)) + if ((skip_insert(node->rrsets, (void *)&rrset->type, (void *)rrset, NULL)) != 0) { return -2; } @@ -53,7 +54,7 @@ int dnslib_node_add_rrset( dnslib_node_t *node, dnslib_rrset_t *rrset ) const dnslib_rrset_t *dnslib_node_get_rrset( const dnslib_node_t *node, uint16_t type ) { - return (dnslib_rrset_t*)skip_find(node->rrsets, (void *)type); + return (dnslib_rrset_t *)skip_find(node->rrsets, (void *)&type); } const dnslib_node_t *dnslib_node_get_parent( const dnslib_node_t *node ) diff --git a/src/tests/dnslib/dnslib_node_tests.c b/src/tests/dnslib/dnslib_node_tests.c index c23e36f47..f15a68476 100644 --- a/src/tests/dnslib/dnslib_node_tests.c +++ b/src/tests/dnslib/dnslib_node_tests.c @@ -149,22 +149,17 @@ static int test_node_sorting() dnslib_node_add_rrset(tmp, rrset); } - int len; + const skip_node *node; - len = skip_length(tmp->rrsets); - - void *array[len]; - - skip_return_list(tmp->rrsets, array); - - int last = ((dnslib_rrset_t *)array[0])->type; + node = skip_first(tmp->rrsets); + + int last = *((int *)node->key); - for (int i = 1; i < len && !errors; i++) { - if (last > ((dnslib_rrset_t *)array[i])->type) { - diag("RRset sorting error."); + while ((node = skip_next(node))!=NULL) { + if (last > *((int *)node->key)) { errors++; + diag("RRset sorting error"); } - last = ((dnslib_rrset_t *)array[i])->type; } return (errors == 0); } diff --git a/src/tests/dnslib/dnslib_rrset_tests.c b/src/tests/dnslib/dnslib_rrset_tests.c index 13bd2eb02..fa14098b0 100644 --- a/src/tests/dnslib/dnslib_rrset_tests.c +++ b/src/tests/dnslib/dnslib_rrset_tests.c @@ -56,7 +56,7 @@ static struct test_rrset test_rrsets[TEST_RRSETS] = { 2, 1, 3600, - (dnslib_rdata_t *) "signature 1", + NULL, NULL, NULL, 0 }, @@ -64,7 +64,7 @@ static struct test_rrset test_rrsets[TEST_RRSETS] = { 2, 1, 3600, - (dnslib_rdata_t *) "signature 2", + NULL, NULL, NULL, 0 }, @@ -72,7 +72,7 @@ static struct test_rrset test_rrsets[TEST_RRSETS] = { 2, 1, 3600, - (dnslib_rdata_t *) "signature 3", + NULL, NULL, NULL, 0 } @@ -83,7 +83,6 @@ static const struct test_rrset test_rrsigs[TEST_RRSIGS] = { 46, 1, 3600, -// {NULL, {"signature data", 1, NULL}}, how to initialize unions? NULL, NULL, NULL, -- GitLab