]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib: refactor the type of funcs which have useless return and checks
authorx2018 <xkernel.wang@foxmail.com>
Thu, 6 Nov 2025 17:59:00 +0000 (01:59 +0800)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 7 Nov 2025 12:01:39 +0000 (13:01 +0100)
Some internal functions always return CURLE_OK.

- Curl_http_proxy_get_destination() does that from bb4032a, (2 years
  ago) And the original inline code does not need to check the status.

- Curl_wildcard_init() does that from e60fe20. (8 years ago)

- Curl_initinfo() does that from a very beginning.

- Curl_pgrsSetDownloadCounter() did not have a return before 914e49b,
  ad051e1 recovered its content (2 years ago) but did not completely
  recovered the changes related to it.

- auth_digest_get_qop_values() does that from 676de7f.

This directly changes their type to void and cleaned the remaining
checks for their return value.

Closes #19386

13 files changed:
lib/cf-h2-proxy.c
lib/ftplistparser.c
lib/ftplistparser.h
lib/getinfo.c
lib/getinfo.h
lib/http_proxy.c
lib/http_proxy.h
lib/progress.c
lib/progress.h
lib/sendf.c
lib/telnet.c
lib/transfer.c
lib/vauth/digest.c

index b0638c6642879ded8e891352d61a10d10404defd..318fe54253fceb50804216179251ebf1b564587c 100644 (file)
@@ -87,7 +87,6 @@ static CURLcode tunnel_stream_init(struct Curl_cfilter *cf,
   const char *hostname;
   int port;
   bool ipv6_ip;
-  CURLcode result;
 
   ts->state = H2_TUNNEL_INIT;
   ts->stream_id = -1;
@@ -95,9 +94,7 @@ static CURLcode tunnel_stream_init(struct Curl_cfilter *cf,
                   BUFQ_OPT_SOFT_LIMIT);
   Curl_bufq_init(&ts->sendbuf, PROXY_H2_CHUNK_SIZE, H2_TUNNEL_SEND_CHUNKS);
 
-  result = Curl_http_proxy_get_destination(cf, &hostname, &port, &ipv6_ip);
-  if(result)
-    return result;
+  Curl_http_proxy_get_destination(cf, &hostname, &port, &ipv6_ip);
 
   /* host:port with IPv6 support */
   ts->authority = curl_maprintf("%s%s%s:%d", ipv6_ip ? "[":"", hostname,
index de573d3c57b52cdcf89d3e3227d2d7f414e5b910..d8d155d5c2ebbe6a235f64ec24e3f1f2cf6fc366 100644 (file)
@@ -185,12 +185,10 @@ static void fileinfo_dtor(void *user, void *element)
   Curl_fileinfo_cleanup(element);
 }
 
-CURLcode Curl_wildcard_init(struct WildcardData *wc)
+void Curl_wildcard_init(struct WildcardData *wc)
 {
   Curl_llist_init(&wc->filelist, fileinfo_dtor);
   wc->state = CURLWC_INIT;
-
-  return CURLE_OK;
 }
 
 void Curl_wildcard_dtor(struct WildcardData **wcp)
index 5ba1f6a97d18f52c842d1299635008965fc6754b..ad8dee74386a116d60949764e80a674bd8bd7844 100644 (file)
@@ -65,7 +65,7 @@ struct WildcardData {
   unsigned char state; /* wildcard_states */
 };
 
-CURLcode Curl_wildcard_init(struct WildcardData *wc);
+void Curl_wildcard_init(struct WildcardData *wc);
 void Curl_wildcard_dtor(struct WildcardData **wcp);
 
 struct Curl_easy;
index e2a8231d53009b095130d2e1ff1363491b760d82..f57a454d5db3a5f80c13c062dff172e4062d47ea 100644 (file)
@@ -45,7 +45,7 @@
  * beginning of a perform session. It must reset the session-info variables,
  * in particular all variables in struct PureInfo.
  */
-CURLcode Curl_initinfo(struct Curl_easy *data)
+void Curl_initinfo(struct Curl_easy *data)
 {
   struct Progress *pro = &data->progress;
   struct PureInfo *info = &data->info;
@@ -91,7 +91,6 @@ CURLcode Curl_initinfo(struct Curl_easy *data)
 #ifdef USE_SSL
   Curl_ssl_free_certinfo(data);
 #endif
-  return CURLE_OK;
 }
 
 static CURLcode getinfo_char(struct Curl_easy *data, CURLINFO info,
index 56bb440b43b2febfe89e1fbf1fb79efa9addb83b..f5efe4185c502e996fd15ada8357181a3c638c6e 100644 (file)
@@ -24,6 +24,6 @@
  *
  ***************************************************************************/
 CURLcode Curl_getinfo(struct Curl_easy *data, CURLINFO info, ...);
-CURLcode Curl_initinfo(struct Curl_easy *data);
+void Curl_initinfo(struct Curl_easy *data);
 
 #endif /* HEADER_CURL_GETINFO_H */
index f6e546b9fd960a9db95e7668842d6d7a8ecb8388..9bde118baff2213b12fd5eccd697e207d7070e62 100644 (file)
@@ -167,9 +167,9 @@ static CURLcode dynhds_add_custom(struct Curl_easy *data,
   return CURLE_OK;
 }
 
-CURLcode Curl_http_proxy_get_destination(struct Curl_cfilter *cf,
-                                         const char **phostname,
-                                         int *pport, bool *pipv6_ip)
+void Curl_http_proxy_get_destination(struct Curl_cfilter *cf,
+                                     const char **phostname,
+                                     int *pport, bool *pipv6_ip)
 {
   DEBUGASSERT(cf);
   DEBUGASSERT(cf->conn);
@@ -192,8 +192,6 @@ CURLcode Curl_http_proxy_get_destination(struct Curl_cfilter *cf,
     *pipv6_ip = (strchr(*phostname, ':') != NULL);
   else
     *pipv6_ip = cf->conn->bits.ipv6_ip;
-
-  return CURLE_OK;
 }
 
 struct cf_proxy_ctx {
@@ -214,9 +212,7 @@ CURLcode Curl_http_proxy_create_CONNECT(struct httpreq **preq,
   CURLcode result;
   struct httpreq *req = NULL;
 
-  result = Curl_http_proxy_get_destination(cf, &hostname, &port, &ipv6_ip);
-  if(result)
-    goto out;
+  Curl_http_proxy_get_destination(cf, &hostname, &port, &ipv6_ip);
 
   authority = curl_maprintf("%s%s%s:%d", ipv6_ip ? "[" : "", hostname,
                             ipv6_ip ?"]" : "", port);
index e6ab2bacf3bbd7ef9e29a92ba92d05e7f1d762e7..17f7e10488e1077d6d79065382842dbf4efa083d 100644 (file)
@@ -36,9 +36,9 @@ enum Curl_proxy_use {
   HEADER_CONNECT  /* sending CONNECT to a proxy */
 };
 
-CURLcode Curl_http_proxy_get_destination(struct Curl_cfilter *cf,
-                                         const char **phostname,
-                                         int *pport, bool *pipv6_ip);
+void Curl_http_proxy_get_destination(struct Curl_cfilter *cf,
+                                     const char **phostname,
+                                     int *pport, bool *pipv6_ip);
 
 CURLcode Curl_http_proxy_create_CONNECT(struct httpreq **preq,
                                         struct Curl_cfilter *cf,
index 7b473ef3ae931a153f7f91ed517026064452a40b..928461043ab26939e03e81bba228b1701f184e44 100644 (file)
@@ -305,10 +305,9 @@ timediff_t Curl_pgrsLimitWaitTime(struct pgrs_dir *d,
 /*
  * Set the number of downloaded bytes so far.
  */
-CURLcode Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size)
+void Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size)
 {
   data->progress.dl.cur_size = size;
-  return CURLE_OK;
 }
 
 /*
index bbe135cdbcd7fbf448418b1520f83fef3b4b075e..7a176b7554accc3de91af49d7c4b46c4615e7dc4 100644 (file)
@@ -48,9 +48,7 @@ void Curl_pgrsStartNow(struct Curl_easy *data);
 void Curl_pgrsSetDownloadSize(struct Curl_easy *data, curl_off_t size);
 void Curl_pgrsSetUploadSize(struct Curl_easy *data, curl_off_t size);
 
-/* It is fine to not check the return code if 'size' is set to 0 */
-CURLcode Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size);
-
+void Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size);
 void Curl_pgrsSetUploadCounter(struct Curl_easy *data, curl_off_t size);
 void Curl_ratelimit(struct Curl_easy *data, struct curltime now);
 int Curl_pgrsUpdate(struct Curl_easy *data);
index f2c29956d1f545d96dda37a981c1180198a58e8a..980fae23e64606984b7195341bd095ac53f916fe 100644 (file)
@@ -316,9 +316,7 @@ static CURLcode cw_download_write(struct Curl_easy *data,
   }
   /* Update stats, write and report progress */
   data->req.bytecount += nwrite;
-  result = Curl_pgrsSetDownloadCounter(data, data->req.bytecount);
-  if(result)
-    return result;
+  Curl_pgrsSetDownloadCounter(data, data->req.bytecount);
 
   if(excess_len) {
     if(!data->req.ignorebody) {
index 5c25bc2eaa36a8a8028ba130e89b5f283e04001c..232e56a8849af4a716b40305a1d04415e971a2a4 100644 (file)
@@ -1599,9 +1599,8 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done)
         }
 
         total_dl += nread;
-        result = Curl_pgrsSetDownloadCounter(data, total_dl);
-        if(!result)
-          result = telrcv(data, tn, (unsigned char *)buffer, nread);
+        Curl_pgrsSetDownloadCounter(data, total_dl);
+        result = telrcv(data, tn, (unsigned char *)buffer, nread);
         if(result) {
           keepon = FALSE;
           break;
index 0269a4c2505fc54c8c132aa2c6cc9d0f386f8939..98168d3aa662e19654cdf40bc6bbaaeedfcb58f1 100644 (file)
@@ -606,9 +606,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data)
           wc->dtor(wc->ftpwc);
         Curl_safefree(wc->pattern);
         Curl_safefree(wc->path);
-        result = Curl_wildcard_init(wc); /* init wildcard structures */
-        if(result)
-          return CURLE_OUT_OF_MEMORY;
+        Curl_wildcard_init(wc); /* init wildcard structures */
       }
     }
 #endif
index 0a0b3580ed0999ccbc15204b94bd4708d6a62a6d..a8d4ffe5b774bdaf28a4a34b61b3f9705d80b83d 100644 (file)
@@ -232,7 +232,7 @@ static bool auth_digest_get_key_value(const char *chlg, const char *key,
   return FALSE;
 }
 
-static CURLcode auth_digest_get_qop_values(const char *options, int *value)
+static void auth_digest_get_qop_values(const char *options, int *value)
 {
   struct Curl_str out;
   /* Initialise the output */
@@ -248,8 +248,6 @@ static CURLcode auth_digest_get_qop_values(const char *options, int *value)
     if(curlx_str_single(&options, ','))
       break;
   }
-
-  return CURLE_OK;
 }
 
 /*
@@ -377,9 +375,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
     return CURLE_BAD_CONTENT_ENCODING;
 
   /* Get the qop-values from the qop-options */
-  result = auth_digest_get_qop_values(qop_options, &qop_values);
-  if(result)
-    return result;
+  auth_digest_get_qop_values(qop_options, &qop_values);
 
   /* We only support auth quality-of-protection */
   if(!(qop_values & DIGEST_QOP_VALUE_AUTH))