From 9a14454d3c5589373253571cee7428c593adefd9 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Thu, 17 Oct 2024 12:16:20 +0200 Subject: Squashed 'dependencies/uthash/' changes from bf152630..f69112c0 f69112c0 utarray: Fix typo in docs 619fe95c Fix MSVC warning C4127 in HASH_BLOOM_TEST (#261) eeba1961 uthash: Improve the docs for HASH_ADD_INORDER ca98384c HASH_DEL should be able to delete a const-qualified node 095425f7 utlist: Add one more assertion in DL_DELETE2 399bf74b utarray: Stop making `oom` a synonym for `utarray_oom` 85bf75ab utarray_str_cpy: Remove strdup; utarray_oom() if strdup fails. 1a53f304 GitHub CI: Also test building the docs (#248) 4d01591e The MCST Elbrus C Compiler supports __typeof. (#247) 1e0baf06 CI: Add GitHub Actions CI 8844b529 Update test57.c per a suggestion by @mark-summerfield 44a66fe8 Update http:// URLs to https://, and copyright dates to 2022. NFC. git-subtree-dir: dependencies/uthash git-subtree-split: f69112c04f1b6e059b8071cb391a1fcc83791a00 --- tests/test57.c | 59 +++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 19 deletions(-) (limited to 'tests/test57.c') diff --git a/tests/test57.c b/tests/test57.c index 3b89fb52d..7ba3b81ae 100644 --- a/tests/test57.c +++ b/tests/test57.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include "uthash.h" typedef struct { @@ -8,25 +8,46 @@ typedef struct { UT_hash_handle hh; } el_t; +el_t *findit(el_t *hash, void *keytofind) +{ + el_t *found; + HASH_FIND_PTR(hash, &keytofind, found); + return found; +} + int main() { - el_t *d; el_t *hash = NULL; - char *someaddr = NULL; - el_t *e = (el_t*)malloc(sizeof(el_t)); - if (!e) { - return -1; - } - e->key = (void*)someaddr; - e->i = 1; - HASH_ADD_PTR(hash,key,e); - HASH_FIND_PTR(hash, &someaddr, d); - if (d != NULL) { - printf("found\n"); - } - - /* release memory */ - HASH_DEL(hash,e); - free(e); + el_t e1; + el_t e2; + + e1.key = NULL; + e1.i = 1; + + e2.key = &e2; + e2.i = 2; + + assert(findit(hash, NULL) == NULL); + assert(findit(hash, &e1) == NULL); + assert(findit(hash, &e2) == NULL); + + HASH_ADD_PTR(hash, key, &e1); + assert(findit(hash, NULL) == &e1); + assert(findit(hash, &e1) == NULL); + assert(findit(hash, &e2) == NULL); + + HASH_ADD_PTR(hash, key, &e2); + assert(findit(hash, NULL) == &e1); + assert(findit(hash, &e1) == NULL); + assert(findit(hash, &e2) == &e2); + + HASH_DEL(hash, &e1); + assert(findit(hash, NULL) == NULL); + assert(findit(hash, &e1) == NULL); + assert(findit(hash, &e2) == &e2); + + HASH_CLEAR(hh, hash); + assert(hash == NULL); + return 0; } -- cgit v1.2.3