From: Alberto Leiva Popper Date: Tue, 7 Jun 2022 18:38:44 +0000 (-0500) Subject: Replace HASH_ADD_KEYPTR with HASH_ADD_STR X-Git-Tag: 1.5.4~11^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03d55369cdc73d012f7e4f1b4ca61ce25bb374b1;p=thirdparty%2FFORT-validator.git Replace HASH_ADD_KEYPTR with HASH_ADD_STR Simplifies the code a bit. These hashes are all string-keyed. --- diff --git a/src/data_structure/uthash_nonfatal.h b/src/data_structure/uthash_nonfatal.h index 39206396..b3b54de6 100644 --- a/src/data_structure/uthash_nonfatal.h +++ b/src/data_structure/uthash_nonfatal.h @@ -15,8 +15,6 @@ * so set 'errno' to 0 before this ops are made. The 'obj' won't be freed, * this is the caller's responsibility. * - * TODO I think most of the code is not checking this. - * * Functions that can OOM: * * HASH_ADD_TO_TABLE @@ -29,13 +27,16 @@ * HASH_ADD_KEYPTR_BYHASHVALUE * HASH_REPLACE_BYHASHVALUE * HASH_REPLACE (*) - * HASH_ADD_KEYPTR (**) + * HASH_REPLACE_STR (**) + * HASH_REPLACE_INT + * HASH_REPLACE_PTR + * HASH_ADD_KEYPTR * HASH_ADD * HASH_ADD_BYHASHVALUE * HASH_SELECT * * (*) Used by Fort - * (**) Used by Fort, but in its fatal uthash form. + * (**) Used by Fort, but only in its fatal uthash form. */ #define HASH_NONFATAL_OOM 1 #define uthash_nonfatal_oom(obj) \ diff --git a/src/reqs_errors.c b/src/reqs_errors.c index 03c3157f..b91b6f0d 100644 --- a/src/reqs_errors.c +++ b/src/reqs_errors.c @@ -177,8 +177,7 @@ reqs_errors_add_uri(char const *uri) (working_repo_peek_level() <= LOG_REPO_LEVEL); rwlock_write_lock(&db_lock); - HASH_ADD_KEYPTR(hh, err_uris_db, new_uri->uri, strlen(new_uri->uri), - new_uri); + HASH_ADD_STR(err_uris_db, uri, new_uri); rwlock_unlock(&db_lock); return 0; diff --git a/src/rrdp/db/db_rrdp_uris.c b/src/rrdp/db/db_rrdp_uris.c index ea9e1533..38a30182 100644 --- a/src/rrdp/db/db_rrdp_uris.c +++ b/src/rrdp/db/db_rrdp_uris.c @@ -94,17 +94,9 @@ add_rrdp_uri(struct db_rrdp_uri *uris, struct uris_table *new_uri) { struct uris_table *old_uri; - /* - * TODO (fine) this should use HASH_REPLACE instead of HASH_ADD_KEYPTR - */ - - old_uri = find_rrdp_uri(uris, new_uri->uri); - if (old_uri != NULL) { - HASH_DELETE(hh, uris->table, old_uri); + HASH_REPLACE_STR(uris->table, uri, new_uri, old_uri); + if (old_uri != NULL) uris_table_destroy(old_uri); - } - HASH_ADD_KEYPTR(hh, uris->table, new_uri->uri, strlen(new_uri->uri), - new_uri); } static int diff --git a/src/visited_uris.c b/src/visited_uris.c index be9fdc8d..af5c0e1a 100644 --- a/src/visited_uris.c +++ b/src/visited_uris.c @@ -114,9 +114,7 @@ visited_uris_add(struct visited_uris *uris, char const *uri) if (error) return error; - HASH_ADD_KEYPTR(hh, uris->table, elem->uri, strlen(elem->uri), - elem); - + HASH_ADD_STR(uris->table, uri, elem); return 0; }