Commit 6d99c96c authored by Daniel Salzman's avatar Daniel Salzman

dname: simplify dname_storage_t usage to mute Coverity

parent 0af1158e
......@@ -719,7 +719,7 @@ static int rr_already_signed(const knot_rrset_t *rrset, trie_t *t,
*rr_signed = false;
// Create a key = RRSet owner converted to sortable format
knot_dname_storage_t lf_storage;
uint8_t *lf = knot_dname_lf(rrset->owner, &lf_storage);
uint8_t *lf = knot_dname_lf(rrset->owner, lf_storage);
assert(lf);
trie_val_t stored_info = (signed_info_t *)trie_get_try(t, (char *)lf+1,
*lf);
......
......@@ -35,7 +35,7 @@ int zone_tree_insert(zone_tree_t *tree, zone_node_t *node)
assert(node->owner);
knot_dname_storage_t lf_storage;
uint8_t *lf = knot_dname_lf(node->owner, &lf_storage);
uint8_t *lf = knot_dname_lf(node->owner, lf_storage);
assert(lf);
*trie_get_ins(tree, (char *)lf + 1, *lf) = node;
......@@ -54,7 +54,7 @@ zone_node_t *zone_tree_get(zone_tree_t *tree, const knot_dname_t *owner)
}
knot_dname_storage_t lf_storage;
uint8_t *lf = knot_dname_lf(owner, &lf_storage);
uint8_t *lf = knot_dname_lf(owner, lf_storage);
assert(lf);
trie_val_t *val = trie_get_try(tree, (char *)lf + 1, *lf);
......@@ -79,7 +79,7 @@ int zone_tree_get_less_or_equal(zone_tree_t *tree,
}
knot_dname_storage_t lf_storage;
uint8_t *lf = knot_dname_lf(owner, &lf_storage);
uint8_t *lf = knot_dname_lf(owner, lf_storage);
assert(lf);
trie_val_t *fval = NULL;
......@@ -123,7 +123,7 @@ static void remove_node(zone_tree_t *tree, const knot_dname_t *owner)
}
knot_dname_storage_t lf_storage;
uint8_t *lf = knot_dname_lf(owner, &lf_storage);
uint8_t *lf = knot_dname_lf(owner, lf_storage);
assert(lf);
trie_val_t *rval = trie_get_try(tree, (char *)lf + 1, *lf);
......
......@@ -70,7 +70,7 @@ int knot_zonedb_insert(knot_zonedb_t *db, zone_t *zone)
assert(zone->name);
knot_dname_storage_t lf_storage;
uint8_t *lf = knot_dname_lf(zone->name, &lf_storage);
uint8_t *lf = knot_dname_lf(zone->name, lf_storage);
assert(lf);
*trie_get_ins(db->trie, (char *)lf + 1, *lf) = zone;
......@@ -85,7 +85,7 @@ int knot_zonedb_del(knot_zonedb_t *db, const knot_dname_t *zone_name)
}
knot_dname_storage_t lf_storage;
uint8_t *lf = knot_dname_lf(zone_name, &lf_storage);
uint8_t *lf = knot_dname_lf(zone_name, lf_storage);
assert(lf);
trie_val_t *rval = trie_get_try(db->trie, (char *)lf + 1, *lf);
......@@ -103,7 +103,7 @@ zone_t *knot_zonedb_find(knot_zonedb_t *db, const knot_dname_t *zone_name)
}
knot_dname_storage_t lf_storage;
uint8_t *lf = knot_dname_lf(zone_name, &lf_storage);
uint8_t *lf = knot_dname_lf(zone_name, lf_storage);
assert(lf);
trie_val_t *val = trie_get_try(db->trie, (char *)lf + 1, *lf);
......@@ -122,7 +122,7 @@ zone_t *knot_zonedb_find_suffix(knot_zonedb_t *db, const knot_dname_t *zone_name
while (true) {
knot_dname_storage_t lf_storage;
uint8_t *lf = knot_dname_lf(zone_name, &lf_storage);
uint8_t *lf = knot_dname_lf(zone_name, lf_storage);
assert(lf);
trie_val_t *val = trie_get_try(db->trie, (char *)lf + 1, *lf);
......
......@@ -161,7 +161,7 @@ knot_dname_t *knot_dname_parse(const uint8_t *pkt, size_t *pos, size_t maxpos,
}
_public_
size_t knot_dname_store(knot_dname_storage_t *dst, const knot_dname_t *name)
size_t knot_dname_store(knot_dname_storage_t dst, const knot_dname_t *name)
{
if (dst == NULL || name == NULL) {
return 0;
......@@ -169,7 +169,7 @@ size_t knot_dname_store(knot_dname_storage_t *dst, const knot_dname_t *name)
size_t len = knot_dname_size(name);
assert(len <= KNOT_DNAME_MAXLEN);
memcpy(dst->data, name, len);
memcpy(dst, name, len);
return len;
}
......@@ -682,8 +682,8 @@ int knot_dname_cmp(const knot_dname_t *d1, const knot_dname_t *d2)
knot_dname_storage_t lf1_storage;
knot_dname_storage_t lf2_storage;
uint8_t *lf1 = knot_dname_lf(d1, &lf1_storage);
uint8_t *lf2 = knot_dname_lf(d2, &lf2_storage);
uint8_t *lf1 = knot_dname_lf(d1, lf1_storage);
uint8_t *lf2 = knot_dname_lf(d2, lf2_storage);
assert(lf1 && lf2);
/* Compare common part. */
......@@ -772,14 +772,14 @@ size_t knot_dname_labels(const uint8_t *name, const uint8_t *pkt)
}
_public_
uint8_t *knot_dname_lf(const knot_dname_t *src, knot_dname_storage_t *storage)
uint8_t *knot_dname_lf(const knot_dname_t *src, knot_dname_storage_t storage)
{
if (src == NULL || storage == NULL) {
return NULL;
}
/* Writing from the end. */
storage->data[KNOT_DNAME_MAXLEN - 1] = '\0';
storage[KNOT_DNAME_MAXLEN - 1] = '\0';
size_t idx = KNOT_DNAME_MAXLEN - 1;
while (*src != 0) {
......@@ -787,14 +787,14 @@ uint8_t *knot_dname_lf(const knot_dname_t *src, knot_dname_storage_t *storage)
assert(idx >= len);
idx -= len;
memcpy(&storage->data[idx], src, len);
storage->data[idx] = '\0';
memcpy(&storage[idx], src, len);
storage[idx] = '\0';
src += len;
}
assert(KNOT_DNAME_MAXLEN >= 1 + idx);
storage->data[idx] = KNOT_DNAME_MAXLEN - 1 - idx;
storage[idx] = KNOT_DNAME_MAXLEN - 1 - idx;
return &storage->data[idx];
return &storage[idx];
}
......@@ -35,10 +35,7 @@
typedef uint8_t knot_dname_t;
/*! \brief Local domain name storage. */
typedef union {
knot_dname_t dname;
uint8_t data[KNOT_DNAME_MAXLEN];
} knot_dname_storage_t;
typedef uint8_t knot_dname_storage_t[KNOT_DNAME_MAXLEN];
/*!
* \brief Check dname on the wire for constraints.
......@@ -81,7 +78,7 @@ knot_dname_t *knot_dname_parse(const uint8_t *pkt, size_t *pos, size_t maxpos,
* \retval 0 if invalid argument.
*/
_mustcheck_
size_t knot_dname_store(knot_dname_storage_t *dst, const knot_dname_t *name);
size_t knot_dname_store(knot_dname_storage_t dst, const knot_dname_t *name);
/*!
* \brief Duplicates the given domain name.
......@@ -353,6 +350,6 @@ size_t knot_dname_labels(const uint8_t *name, const uint8_t *pkt);
* \retval Lookup format if successful (pointer into the storage).
* \retval NULL on invalid parameters.
*/
uint8_t *knot_dname_lf(const knot_dname_t *src, knot_dname_storage_t *storage);
uint8_t *knot_dname_lf(const knot_dname_t *src, knot_dname_storage_t storage);
/*! @} */
......@@ -128,13 +128,13 @@ static void test_dname_lf(void)
"ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg""\x00"
"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh""\x00"
"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii""\x00";
uint8_t *out = knot_dname_lf(in, &storage);
uint8_t *out = knot_dname_lf(in, storage);
ok(out != NULL && memcmp(ref, out, KNOT_DNAME_MAXLEN) == 0,
"knot_dname_lf: max-length DNAME converted");
/* Zero label DNAME*/
in = (uint8_t *) "\x00";
out = knot_dname_lf(in, &storage);
out = knot_dname_lf(in, storage);
ok(out != NULL && out[0] == '\x00', "knot_dname_lf: zero-label DNAME converted");
}
......@@ -144,13 +144,11 @@ static void test_dname_storage(void)
size_t dname_len = knot_dname_size(dname);
knot_dname_storage_t storage;
size_t store_len = knot_dname_store(&storage, dname);
size_t storage_len = knot_dname_size(&storage.dname);
size_t store_len = knot_dname_store(storage, dname);
size_t storage_len = knot_dname_size(storage);
ok(store_len == dname_len && storage_len == dname_len &&
memcmp(&storage, dname, dname_len) == 0 &&
memcmp(&storage.data, dname, dname_len) == 0 &&
memcmp(&storage.dname, dname, dname_len) == 0,
memcmp(storage, dname, dname_len) == 0,
"knot_dname_storage: valid name");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment