aboutsummaryrefslogtreecommitdiffstats
path: root/t/unit-tests
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-10-02 12:56:25 +0200
committerJunio C Hamano <gitster@pobox.com>2024-10-02 07:53:55 -0700
commit51afc709dc2f502442220954fb3e32f53eeb1e4e (patch)
tree4a91fe0c5f9ef68463ba8c3330c6068e63065498 /t/unit-tests
parentd0501c8c9d0b67587e112bbe2a85746c7c11a9e8 (diff)
downloadgit-51afc709dc2f502442220954fb3e32f53eeb1e4e.tar.gz
reftable/tree: handle allocation failures
The tree interfaces of the reftable library handle both insertion and searching of tree nodes with a single function, where the behaviour is altered between the two via an `insert` bit. This makes it quit awkward to handle allocation failures because on inserting we'd have to check for `NULL` pointers and return an error, whereas on searching entries we don't have to handle it as an allocation error. Split up concerns of this function into two separate functions, one for inserting entries and one for searching entries. This makes it easy for us to check for allocation errors as `tree_insert()` should never return a `NULL` pointer now. Adapt callers accordingly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/unit-tests')
-rw-r--r--t/unit-tests/t-reftable-tree.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/t/unit-tests/t-reftable-tree.c b/t/unit-tests/t-reftable-tree.c
index 700479d34b..79b175a45a 100644
--- a/t/unit-tests/t-reftable-tree.c
+++ b/t/unit-tests/t-reftable-tree.c
@@ -37,16 +37,17 @@ static void t_tree_search(void)
* values[1] and values[10] (inclusive) in the tree.
*/
do {
- nodes[i] = tree_search(&values[i], &root, &t_compare, 1);
+ nodes[i] = tree_insert(&root, &values[i], &t_compare);
+ check(nodes[i] != NULL);
i = (i * 7) % 11;
} while (i != 1);
for (i = 1; i < ARRAY_SIZE(nodes); i++) {
check_pointer_eq(&values[i], nodes[i]->key);
- check_pointer_eq(nodes[i], tree_search(&values[i], &root, &t_compare, 0));
+ check_pointer_eq(nodes[i], tree_search(root, &values[i], &t_compare));
}
- check(!tree_search(values, &root, t_compare, 0));
+ check(!tree_search(root, values, t_compare));
tree_free(root);
}
@@ -62,7 +63,8 @@ static void t_infix_walk(void)
size_t count = 0;
do {
- tree_search(&values[i], &root, t_compare, 1);
+ struct tree_node *node = tree_insert(&root, &values[i], t_compare);
+ check(node != NULL);
i = (i * 7) % 11;
count++;
} while (i != 1);