]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Replace HASH_ADD_KEYPTR with HASH_ADD_STR
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Tue, 7 Jun 2022 18:38:44 +0000 (13:38 -0500)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Tue, 7 Jun 2022 18:38:44 +0000 (13:38 -0500)
Simplifies the code a bit. These hashes are all string-keyed.

src/data_structure/uthash_nonfatal.h
src/reqs_errors.c
src/rrdp/db/db_rrdp_uris.c
src/visited_uris.c

index 3920639661092947e794f2faec366d57d9099db7..b3b54de62b972d6eb55d93f6e3f34a71d4ad0e24 100644 (file)
@@ -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
  *             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)                                       \
index 03c3157f5b7c909c99e41ff2e48acc35f90c5e13..b91b6f0de89c2e1a56b5281e2e517349356bd368 100644 (file)
@@ -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;
index ea9e1533a367ff6f1f4fcdc11178ed004a130303..38a3018276b8b571ae6eb0791987cfd16111814a 100644 (file)
@@ -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
index be9fdc8da0bc5995fd8d10d4d3f03bb80f2c9b5a..af5c0e1a43c47d9ca08fa2c77008f813aba1a744 100644 (file)
@@ -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;
 }