]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
metahash: add asserts to help analyzers
authorDaniel Stenberg <daniel@haxx.se>
Wed, 7 May 2025 08:49:13 +0000 (10:49 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 7 May 2025 09:25:14 +0000 (11:25 +0200)
Where NULL pointers are not acceptable input.

Closes #17268

lib/easy.c
lib/ftp.c
lib/pop3.c

index 67064f2bc23bd946a176ab241bc15aeebaa63827..4dab47284a0ec67cbd2a4d31b18415a512d4464f 100644 (file)
@@ -1390,6 +1390,7 @@ CURLcode curl_easy_ssls_export(CURL *d,
 CURLcode Curl_meta_set(struct Curl_easy *data, const char *key,
                        void *meta_data, Curl_meta_dtor *meta_dtor)
 {
+  DEBUGASSERT(meta_data); /* never set to NULL */
   if(!Curl_hash_add2(&data->meta_hash, CURL_UNCONST(key), strlen(key) + 1,
                      meta_data, meta_dtor)) {
     meta_dtor(CURL_UNCONST(key), strlen(key) + 1, meta_data);
index d78a13ed824c2a98de86e1d88c6ceecd8c2466c4..40e08be47b731382f62d854be6139c56cba4f00d 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -4412,7 +4412,7 @@ static CURLcode ftp_setup_connection(struct Curl_easy *data,
 
   ftp = calloc(1, sizeof(*ftp));
   if(!ftp ||
-    Curl_meta_set(data, CURL_META_FTP_EASY, ftp, ftp_easy_dtor))
+     Curl_meta_set(data, CURL_META_FTP_EASY, ftp, ftp_easy_dtor))
     return CURLE_OUT_OF_MEMORY;
 
   ftpc = calloc(1, sizeof(*ftpc));
index 84570fd913f00188aea6f192413e5aac894bcb64..62d2e26addc370bddd8dd5962c619f008dc29a26 100644 (file)
@@ -1534,6 +1534,7 @@ static void pop3_easy_dtor(void *key, size_t klen, void *entry)
   struct POP3 *pop3 = entry;
   (void)key;
   (void)klen;
+  DEBUGASSERT(pop3);
   /* Cleanup our per-request based variables */
   Curl_safefree(pop3->id);
   Curl_safefree(pop3->custom);
@@ -1545,6 +1546,7 @@ static void pop3_conn_dtor(void *key, size_t klen, void *entry)
   struct pop3_conn *pop3c = entry;
   (void)key;
   (void)klen;
+  DEBUGASSERT(pop3c);
   Curl_pp_disconnect(&pop3c->pp);
   Curl_safefree(pop3c->apoptimestamp);
   free(pop3c);
@@ -1556,12 +1558,12 @@ static CURLcode pop3_setup_connection(struct Curl_easy *data,
   struct pop3_conn *pop3c;
   struct POP3 *pop3 = calloc(1, sizeof(*pop3));
   if(!pop3 ||
-    Curl_meta_set(data, CURL_META_POP3_EASY, pop3, pop3_easy_dtor))
+     Curl_meta_set(data, CURL_META_POP3_EASY, pop3, pop3_easy_dtor))
     return CURLE_OUT_OF_MEMORY;
 
   pop3c = calloc(1, sizeof(*pop3c));
   if(!pop3c ||
-    Curl_conn_meta_set(conn, CURL_META_POP3_CONN, pop3c, pop3_conn_dtor))
+     Curl_conn_meta_set(conn, CURL_META_POP3_CONN, pop3c, pop3_conn_dtor))
     return CURLE_OUT_OF_MEMORY;
 
   return CURLE_OK;