From: x2018 Date: Thu, 6 Nov 2025 17:59:00 +0000 (+0800) Subject: lib: refactor the type of funcs which have useless return and checks X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=608d96694b392a96e448de266a41fc65607150b9;p=thirdparty%2Fcurl.git lib: refactor the type of funcs which have useless return and checks 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 --- diff --git a/lib/cf-h2-proxy.c b/lib/cf-h2-proxy.c index b0638c6642..318fe54253 100644 --- a/lib/cf-h2-proxy.c +++ b/lib/cf-h2-proxy.c @@ -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, diff --git a/lib/ftplistparser.c b/lib/ftplistparser.c index de573d3c57..d8d155d5c2 100644 --- a/lib/ftplistparser.c +++ b/lib/ftplistparser.c @@ -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) diff --git a/lib/ftplistparser.h b/lib/ftplistparser.h index 5ba1f6a97d..ad8dee7438 100644 --- a/lib/ftplistparser.h +++ b/lib/ftplistparser.h @@ -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; diff --git a/lib/getinfo.c b/lib/getinfo.c index e2a8231d53..f57a454d5d 100644 --- a/lib/getinfo.c +++ b/lib/getinfo.c @@ -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, diff --git a/lib/getinfo.h b/lib/getinfo.h index 56bb440b43..f5efe4185c 100644 --- a/lib/getinfo.h +++ b/lib/getinfo.h @@ -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 */ diff --git a/lib/http_proxy.c b/lib/http_proxy.c index f6e546b9fd..9bde118baf 100644 --- a/lib/http_proxy.c +++ b/lib/http_proxy.c @@ -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); diff --git a/lib/http_proxy.h b/lib/http_proxy.h index e6ab2bacf3..17f7e10488 100644 --- a/lib/http_proxy.h +++ b/lib/http_proxy.h @@ -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, diff --git a/lib/progress.c b/lib/progress.c index 7b473ef3ae..928461043a 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -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; } /* diff --git a/lib/progress.h b/lib/progress.h index bbe135cdbc..7a176b7554 100644 --- a/lib/progress.h +++ b/lib/progress.h @@ -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); diff --git a/lib/sendf.c b/lib/sendf.c index f2c29956d1..980fae23e6 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -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) { diff --git a/lib/telnet.c b/lib/telnet.c index 5c25bc2eaa..232e56a884 100644 --- a/lib/telnet.c +++ b/lib/telnet.c @@ -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; diff --git a/lib/transfer.c b/lib/transfer.c index 0269a4c250..98168d3aa6 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -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 diff --git a/lib/vauth/digest.c b/lib/vauth/digest.c index 0a0b3580ed..a8d4ffe5b7 100644 --- a/lib/vauth/digest.c +++ b/lib/vauth/digest.c @@ -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))