diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2021-09-15 17:04:21 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2021-09-15 17:04:21 +0200 |
commit | 1fa53c5bf8d0717f784c79abaa5111f88ab00221 (patch) | |
tree | 5003411ee362757cb14882bd3d92c98ce8ce3dff /tests/test93.c | |
parent | c8bf38e5fb717d40635a2a89b22ed71b0de4266b (diff) |
Squashed 'dependencies/uthash/' changes from 8e67ced..bf15263
bf15263 Fix a "bug" in the example where option 3 interfered with option 1's counter.
b6e24ef Use `malloc(sizeof *s)` in example code.
a109c6b Stop using `gets` in example.c.
c85c9e1 fix: fix utstack example's compiling error
86e6776 Replace *.github.com urls with *.github.io (#227)
e493aa9 Bump version to 2.3.0.
ae2ac52 Fix README.md to display the *actual* TravisCI status.
134e241 Silence -Wswitch-default warnings, and add it to the TravisCI config.
62fefa6 Fix some typos in userguide.txt, and re-remove spaces in macro definitions.
37d2021 tests: add whitespaces to example code
524ca1a doc: add whitespaces to documentation
0f6c619 Fix a typo in the documentation for HASH_COUNT. NFC.
388134a Rename uthash_memcmp to HASH_KEYCMP, step 3.
053bed1 Eliminate HASH_FCN; change the handling of HASH_FUNCTION to match HASH_KEYCMP.
f0e1bd9 Refactor test93.c to avoid scan-build warnings.
45af88c Remove two dead writes in tests, to silence scan-build warnings.
66e2668 Bump version to 2.2.0.
973bd67 uthash.h: Swap multiplicands to put the widest ones first.
15ad042 Always include <stdint.h>, unless HASH_NO_STDINT is defined by the user.
6b4768b Rename uthash_memcmp to HASH_KEYCMP, step 2.
e64c7f0 Update tests/README to describe the most recently added tests. NFC.
c62796c HASH_CLEAR after some tests, to eliminate "memory leak" warnings.
7f0aadb Support spaces in $exe path
0831d9a uthash.h: fix compiler warning -Wcast-qual
ba2fbfd utarray.h: preserve constness in utarray_str_cpy
git-subtree-dir: dependencies/uthash
git-subtree-split: bf15263081be6229be31addd48566df93921cb46
Diffstat (limited to 'tests/test93.c')
-rw-r--r-- | tests/test93.c | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/tests/test93.c b/tests/test93.c index 4afe7d51e..81103a1a7 100644 --- a/tests/test93.c +++ b/tests/test93.c @@ -39,43 +39,39 @@ static void alt_fatal(char const * s) { longjmp(j_buf, 1); } -static example_user_t * init_user(int need_malloc_cnt) { - users = 0; +static void init_users(int need_malloc_cnt) { + users = NULL; example_user_t * user = (example_user_t*)malloc(sizeof(example_user_t)); user->id = user_id; is_fatal = 0; malloc_cnt = need_malloc_cnt; - /* printf("adding to hash...\n"); */ if (!setjmp(j_buf)) { HASH_ADD_INT(users, id, user); + } else { + free(user); } - return user; } int main() { + example_user_t *user; -#define init(a) do { \ -} while(0) - - example_user_t * user; - - user = init_user(3); /* bloom filter must fail */ + init_users(3); /* bloom filter must fail */ if (!is_fatal) { printf("fatal not called after bloom failure\n"); } - user = init_user(2); /* bucket creation must fail */ + init_users(2); /* bucket creation must fail */ if (!is_fatal) { printf("fatal not called after bucket creation failure\n"); } - user = init_user(1); /* table creation must fail */ + init_users(1); /* table creation must fail */ if (!is_fatal) { printf("fatal not called after table creation failure\n"); } - user = init_user(4); /* hash must create OK */ + init_users(4); /* hash must create OK */ if (is_fatal) { printf("fatal error when creating hash normally\n"); /* bad idea to continue running */ @@ -83,19 +79,20 @@ int main() } /* let's add users until expansion fails */ - users = 0; + users = NULL; malloc_cnt = 4; while (1) { - user = (example_user_t*)malloc(sizeof(example_user_t)); - user->id = user_id; if (user_id++ == 1000) { printf("there is no way 1000 iterations didn't require realloc\n"); break; } + user = (example_user_t*)malloc(sizeof(example_user_t)); + user->id = user_id; if (!setjmp(j_buf)) { HASH_ADD_INT(users, id, user); + } else { + free(user); } - malloc_cnt = 0; if (malloc_failed) { if (!is_fatal) { @@ -108,12 +105,12 @@ int main() /* we can't really do anything, the hash is not in consistent * state, so assume this is a success. */ break; - } + malloc_cnt = 0; } - printf("End\n"); + HASH_CLEAR(hh, users); + printf("End\n"); return 0; - } |