lib: reserve 'result' for CURLcode, even more

Closes #21245
This commit is contained in:
Daniel Stenberg 2026-04-06 23:27:36 +02:00
parent fc3261b284
commit be92f0a2e4
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
8 changed files with 76 additions and 79 deletions

View file

@ -600,7 +600,7 @@ bool Curl_cpool_find(struct Curl_easy *data,
{ {
struct cpool *cpool = cpool_get_instance(data); struct cpool *cpool = cpool_get_instance(data);
struct cpool_bundle *bundle; struct cpool_bundle *bundle;
bool result = FALSE; bool found = FALSE;
DEBUGASSERT(cpool); DEBUGASSERT(cpool);
DEBUGASSERT(conn_cb); DEBUGASSERT(conn_cb);
@ -619,17 +619,17 @@ bool Curl_cpool_find(struct Curl_easy *data,
curr = Curl_node_next(curr); curr = Curl_node_next(curr);
if(conn_cb(conn, userdata)) { if(conn_cb(conn, userdata)) {
result = TRUE; found = TRUE;
break; break;
} }
} }
} }
if(done_cb) { if(done_cb) {
result = done_cb(userdata); found = done_cb(userdata);
} }
CPOOL_UNLOCK(cpool, data); CPOOL_UNLOCK(cpool, data);
return result; return found;
} }
void Curl_conn_terminate(struct Curl_easy *data, void Curl_conn_terminate(struct Curl_easy *data,

View file

@ -609,11 +609,11 @@ CURLFORMcode curl_formadd(struct curl_httppost **httppost,
struct curl_httppost **last_post, ...) struct curl_httppost **last_post, ...)
{ {
va_list arg; va_list arg;
CURLFORMcode result; CURLFORMcode form;
va_start(arg, last_post); va_start(arg, last_post);
result = FormAdd(httppost, last_post, arg); form = FormAdd(httppost, last_post, arg);
va_end(arg); va_end(arg);
return result; return form;
} }
/* /*

View file

@ -3170,13 +3170,13 @@ static statusline checkhttpprefix(struct Curl_easy *data,
static statusline checkrtspprefix(struct Curl_easy *data, static statusline checkrtspprefix(struct Curl_easy *data,
const char *s, size_t len) const char *s, size_t len)
{ {
statusline result = STATUS_BAD; statusline status = STATUS_BAD;
statusline onmatch = len >= 5 ? STATUS_DONE : STATUS_UNKNOWN; statusline onmatch = len >= 5 ? STATUS_DONE : STATUS_UNKNOWN;
(void)data; (void)data;
if(checkprefixmax("RTSP/", s, len)) if(checkprefixmax("RTSP/", s, len))
result = onmatch; status = onmatch;
return result; return status;
} }
#endif /* CURL_DISABLE_RTSP */ #endif /* CURL_DISABLE_RTSP */

View file

@ -485,7 +485,7 @@ static bool smtp_endofresp(struct Curl_easy *data, struct connectdata *conn,
const char *line, size_t len, int *resp) const char *line, size_t len, int *resp)
{ {
struct smtp_conn *smtpc = Curl_conn_meta_get(conn, CURL_META_SMTP_CONN); struct smtp_conn *smtpc = Curl_conn_meta_get(conn, CURL_META_SMTP_CONN);
bool result = FALSE; bool end = FALSE;
(void)data; (void)data;
DEBUGASSERT(smtpc); DEBUGASSERT(smtpc);
@ -504,7 +504,7 @@ static bool smtp_endofresp(struct Curl_easy *data, struct connectdata *conn,
char tmpline[6]; char tmpline[6];
curl_off_t code; curl_off_t code;
const char *p = tmpline; const char *p = tmpline;
result = TRUE; end = TRUE;
memcpy(tmpline, line, (len == 5 ? 5 : 3)); memcpy(tmpline, line, (len == 5 ? 5 : 3));
tmpline[len == 5 ? 5 : 3] = 0; tmpline[len == 5 ? 5 : 3] = 0;
if(curlx_str_number(&p, &code, len == 5 ? 99999 : 999)) if(curlx_str_number(&p, &code, len == 5 ? 99999 : 999))
@ -518,11 +518,11 @@ static bool smtp_endofresp(struct Curl_easy *data, struct connectdata *conn,
/* Do we have a multiline (continuation) response? */ /* Do we have a multiline (continuation) response? */
else if(line[3] == '-' && else if(line[3] == '-' &&
(smtpc->state == SMTP_EHLO || smtpc->state == SMTP_COMMAND)) { (smtpc->state == SMTP_EHLO || smtpc->state == SMTP_COMMAND)) {
result = TRUE; end = TRUE;
*resp = 1; /* Internal response code */ *resp = 1; /* Internal response code */
} }
return result; return end;
} }
/*********************************************************************** /***********************************************************************

View file

@ -1305,7 +1305,7 @@ static bool url_attach_existing(struct Curl_easy *data,
bool *waitpipe) bool *waitpipe)
{ {
struct url_conn_match match; struct url_conn_match match;
bool result; bool success;
DEBUGASSERT(!data->conn); DEBUGASSERT(!data->conn);
memset(&match, 0, sizeof(match)); memset(&match, 0, sizeof(match));
@ -1340,13 +1340,13 @@ static bool url_attach_existing(struct Curl_easy *data,
/* Find a connection in the pool that matches what "data + needle" /* Find a connection in the pool that matches what "data + needle"
* requires. If a suitable candidate is found, it is attached to "data". */ * requires. If a suitable candidate is found, it is attached to "data". */
result = Curl_cpool_find(data, needle->destination, success = Curl_cpool_find(data, needle->destination,
url_match_conn, url_match_result, &match); url_match_conn, url_match_result, &match);
/* wait_pipe is TRUE if we encounter a bundle that is undecided. There /* wait_pipe is TRUE if we encounter a bundle that is undecided. There
* is no matching connection then, yet. */ * is no matching connection then, yet. */
*waitpipe = (bool)match.wait_pipe; *waitpipe = (bool)match.wait_pipe;
return result; return success;
} }
/* /*

View file

@ -251,7 +251,7 @@ static CURLUcode parse_hostname_login(struct Curl_URL *u,
unsigned int flags, unsigned int flags,
size_t *offset) /* to the hostname */ size_t *offset) /* to the hostname */
{ {
CURLUcode result = CURLUE_OK; CURLUcode ures = CURLUE_OK;
CURLcode ccode; CURLcode ccode;
char *userp = NULL; char *userp = NULL;
char *passwdp = NULL; char *passwdp = NULL;
@ -292,14 +292,14 @@ static CURLUcode parse_hostname_login(struct Curl_URL *u,
if(ccode) { if(ccode) {
/* the only possible error from Curl_parse_login_details is out of /* the only possible error from Curl_parse_login_details is out of
memory: */ memory: */
result = CURLUE_OUT_OF_MEMORY; ures = CURLUE_OUT_OF_MEMORY;
goto out; goto out;
} }
if(userp) { if(userp) {
if(flags & CURLU_DISALLOW_USER) { if(flags & CURLU_DISALLOW_USER) {
/* Option DISALLOW_USER is set and URL contains username. */ /* Option DISALLOW_USER is set and URL contains username. */
result = CURLUE_USER_NOT_ALLOWED; ures = CURLUE_USER_NOT_ALLOWED;
goto out; goto out;
} }
curlx_free(u->user); curlx_free(u->user);
@ -329,7 +329,7 @@ out:
u->password = NULL; u->password = NULL;
u->options = NULL; u->options = NULL;
return result; return ures;
} }
UNITTEST CURLUcode Curl_parse_port(struct Curl_URL *u, struct dynbuf *host, UNITTEST CURLUcode Curl_parse_port(struct Curl_URL *u, struct dynbuf *host,
@ -659,21 +659,21 @@ out:
/* used for HTTP/2 server push */ /* used for HTTP/2 server push */
CURLUcode Curl_url_set_authority(CURLU *u, const char *authority) CURLUcode Curl_url_set_authority(CURLU *u, const char *authority)
{ {
CURLUcode result; CURLUcode ures;
struct dynbuf host; struct dynbuf host;
DEBUGASSERT(authority); DEBUGASSERT(authority);
curlx_dyn_init(&host, CURL_MAX_INPUT_LENGTH); curlx_dyn_init(&host, CURL_MAX_INPUT_LENGTH);
result = parse_authority(u, authority, strlen(authority), ures = parse_authority(u, authority, strlen(authority),
CURLU_DISALLOW_USER, &host, !!u->scheme); CURLU_DISALLOW_USER, &host, !!u->scheme);
if(result) if(ures)
curlx_dyn_free(&host); curlx_dyn_free(&host);
else { else {
curlx_free(u->host); curlx_free(u->host);
u->host = curlx_dyn_ptr(&host); u->host = curlx_dyn_ptr(&host);
} }
return result; return ures;
} }
/* /*
@ -1012,16 +1012,16 @@ static CURLUcode guess_scheme(CURLU *u, struct dynbuf *host)
static CURLUcode handle_fragment(CURLU *u, const char *fragment, static CURLUcode handle_fragment(CURLU *u, const char *fragment,
size_t fraglen, unsigned int flags) size_t fraglen, unsigned int flags)
{ {
CURLUcode result; CURLUcode ures;
u->fragment_present = TRUE; u->fragment_present = TRUE;
if(fraglen > 1) { if(fraglen > 1) {
/* skip the leading '#' in the copy but include the terminating null */ /* skip the leading '#' in the copy but include the terminating null */
if(flags & CURLU_URLENCODE) { if(flags & CURLU_URLENCODE) {
struct dynbuf enc; struct dynbuf enc;
curlx_dyn_init(&enc, CURL_MAX_INPUT_LENGTH); curlx_dyn_init(&enc, CURL_MAX_INPUT_LENGTH);
result = urlencode_str(&enc, fragment + 1, fraglen - 1, TRUE, FALSE); ures = urlencode_str(&enc, fragment + 1, fraglen - 1, TRUE, FALSE);
if(result) if(ures)
return result; return ures;
u->fragment = curlx_dyn_ptr(&enc); u->fragment = curlx_dyn_ptr(&enc);
} }
else { else {
@ -1040,12 +1040,12 @@ static CURLUcode handle_query(CURLU *u, const char *query,
if(qlen > 1) { if(qlen > 1) {
if(flags & CURLU_URLENCODE) { if(flags & CURLU_URLENCODE) {
struct dynbuf enc; struct dynbuf enc;
CURLUcode result; CURLUcode ures;
curlx_dyn_init(&enc, CURL_MAX_INPUT_LENGTH); curlx_dyn_init(&enc, CURL_MAX_INPUT_LENGTH);
/* skip the leading question mark */ /* skip the leading question mark */
result = urlencode_str(&enc, query + 1, qlen - 1, TRUE, TRUE); ures = urlencode_str(&enc, query + 1, qlen - 1, TRUE, TRUE);
if(result) if(ures)
return result; return ures;
u->query = curlx_dyn_ptr(&enc); u->query = curlx_dyn_ptr(&enc);
} }
else { else {
@ -1067,13 +1067,13 @@ static CURLUcode handle_path(CURLU *u, const char *path,
size_t pathlen, unsigned int flags, size_t pathlen, unsigned int flags,
bool is_file) bool is_file)
{ {
CURLUcode result; CURLUcode ures;
if(pathlen && (flags & CURLU_URLENCODE)) { if(pathlen && (flags & CURLU_URLENCODE)) {
struct dynbuf enc; struct dynbuf enc;
curlx_dyn_init(&enc, CURL_MAX_INPUT_LENGTH); curlx_dyn_init(&enc, CURL_MAX_INPUT_LENGTH);
result = urlencode_str(&enc, path, pathlen, TRUE, FALSE); ures = urlencode_str(&enc, path, pathlen, TRUE, FALSE);
if(result) if(ures)
return result; return ures;
pathlen = curlx_dyn_len(&enc); pathlen = curlx_dyn_len(&enc);
path = u->path = curlx_dyn_ptr(&enc); path = u->path = curlx_dyn_ptr(&enc);
} }
@ -1112,7 +1112,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags)
char schemebuf[MAX_SCHEME_LEN + 1]; char schemebuf[MAX_SCHEME_LEN + 1];
size_t schemelen = 0; size_t schemelen = 0;
size_t urllen; size_t urllen;
CURLUcode result = CURLUE_OK; CURLUcode ures = CURLUE_OK;
struct dynbuf host; struct dynbuf host;
bool is_file = FALSE; bool is_file = FALSE;
@ -1120,8 +1120,8 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags)
curlx_dyn_init(&host, CURL_MAX_INPUT_LENGTH); curlx_dyn_init(&host, CURL_MAX_INPUT_LENGTH);
result = Curl_junkscan(url, &urllen, !!(flags & CURLU_ALLOW_SPACE)); ures = Curl_junkscan(url, &urllen, !!(flags & CURLU_ALLOW_SPACE));
if(result) if(ures)
goto fail; goto fail;
schemelen = Curl_is_absolute_url(url, schemebuf, sizeof(schemebuf), schemelen = Curl_is_absolute_url(url, schemebuf, sizeof(schemebuf),
@ -1131,13 +1131,13 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags)
/* handle the file: scheme */ /* handle the file: scheme */
if(schemelen && !strcmp(schemebuf, "file")) { if(schemelen && !strcmp(schemebuf, "file")) {
is_file = TRUE; is_file = TRUE;
result = parse_file(url, urllen, u, &host, &path, &pathlen); ures = parse_file(url, urllen, u, &host, &path, &pathlen);
} }
else { else {
const char *hostp = NULL; const char *hostp = NULL;
size_t hostlen; size_t hostlen;
result = parse_scheme(url, u, schemebuf, schemelen, flags, &hostp); ures = parse_scheme(url, u, schemebuf, schemelen, flags, &hostp);
if(result) if(ures)
goto fail; goto fail;
/* find the end of the hostname + port number */ /* find the end of the hostname + port number */
@ -1147,49 +1147,49 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags)
/* this pathlen also contains the query and the fragment */ /* this pathlen also contains the query and the fragment */
pathlen = urllen - (path - url); pathlen = urllen - (path - url);
if(hostlen) { if(hostlen) {
result = parse_authority(u, hostp, hostlen, flags, &host, ures = parse_authority(u, hostp, hostlen, flags, &host,
u->scheme != NULL); u->scheme != NULL);
if(!result && (flags & CURLU_GUESS_SCHEME) && !u->scheme) if(!ures && (flags & CURLU_GUESS_SCHEME) && !u->scheme)
result = guess_scheme(u, &host); ures = guess_scheme(u, &host);
} }
else if(flags & CURLU_NO_AUTHORITY) { else if(flags & CURLU_NO_AUTHORITY) {
/* allowed to be empty. */ /* allowed to be empty. */
if(curlx_dyn_add(&host, "")) if(curlx_dyn_add(&host, ""))
result = CURLUE_OUT_OF_MEMORY; ures = CURLUE_OUT_OF_MEMORY;
} }
else else
result = CURLUE_NO_HOST; ures = CURLUE_NO_HOST;
} }
if(!result) { if(!ures) {
/* The path might at this point contain a fragment and/or a query to /* The path might at this point contain a fragment and/or a query to
handle */ handle */
const char *fragment = strchr(path, '#'); const char *fragment = strchr(path, '#');
if(fragment) { if(fragment) {
size_t fraglen = pathlen - (fragment - path); size_t fraglen = pathlen - (fragment - path);
result = handle_fragment(u, fragment, fraglen, flags); ures = handle_fragment(u, fragment, fraglen, flags);
/* after this, pathlen still contains the query */ /* after this, pathlen still contains the query */
pathlen -= fraglen; pathlen -= fraglen;
} }
} }
if(!result) { if(!ures) {
const char *query = memchr(path, '?', pathlen); const char *query = memchr(path, '?', pathlen);
if(query) { if(query) {
size_t qlen = pathlen - (query - path); size_t qlen = pathlen - (query - path);
result = handle_query(u, query, qlen, flags); ures = handle_query(u, query, qlen, flags);
pathlen -= qlen; pathlen -= qlen;
} }
} }
if(!result) if(!ures)
/* the fragment and query parts are trimmed off from the path */ /* the fragment and query parts are trimmed off from the path */
result = handle_path(u, path, pathlen, flags, is_file); ures = handle_path(u, path, pathlen, flags, is_file);
if(!result) { if(!ures) {
u->host = curlx_dyn_ptr(&host); u->host = curlx_dyn_ptr(&host);
return CURLUE_OK; return CURLUE_OK;
} }
fail: fail:
curlx_dyn_free(&host); curlx_dyn_free(&host);
free_urlhandle(u); free_urlhandle(u);
return result; return ures;
} }
/* /*
@ -1198,15 +1198,15 @@ fail:
static CURLUcode parseurl_and_replace(const char *url, CURLU *u, static CURLUcode parseurl_and_replace(const char *url, CURLU *u,
unsigned int flags) unsigned int flags)
{ {
CURLUcode result; CURLUcode ures;
CURLU tmpurl; CURLU tmpurl;
memset(&tmpurl, 0, sizeof(tmpurl)); memset(&tmpurl, 0, sizeof(tmpurl));
result = parseurl(url, &tmpurl, flags); ures = parseurl(url, &tmpurl, flags);
if(!result) { if(!ures) {
free_urlhandle(u); free_urlhandle(u);
*u = tmpurl; *u = tmpurl;
} }
return result; return ures;
} }
/* /*

View file

@ -438,13 +438,12 @@ static DWORD cert_get_name_string(struct Curl_easy *data,
static bool get_num_host_info(struct num_ip_data *ip_blob, LPCSTR hostname) static bool get_num_host_info(struct num_ip_data *ip_blob, LPCSTR hostname)
{ {
bool result = FALSE;
struct in_addr ia; struct in_addr ia;
int res = curlx_inet_pton(AF_INET, hostname, &ia); int res = curlx_inet_pton(AF_INET, hostname, &ia);
if(res) { if(res) {
ip_blob->size = sizeof(struct in_addr); ip_blob->size = sizeof(struct in_addr);
memcpy(&ip_blob->bData.ia, &ia, sizeof(struct in_addr)); memcpy(&ip_blob->bData.ia, &ia, sizeof(struct in_addr));
result = TRUE; return TRUE;
} }
else { else {
struct in6_addr ia6; struct in6_addr ia6;
@ -452,10 +451,10 @@ static bool get_num_host_info(struct num_ip_data *ip_blob, LPCSTR hostname)
if(res) { if(res) {
ip_blob->size = sizeof(struct in6_addr); ip_blob->size = sizeof(struct in6_addr);
memcpy(&ip_blob->bData.ia6, &ia6, sizeof(struct in6_addr)); memcpy(&ip_blob->bData.ia6, &ia6, sizeof(struct in6_addr));
result = TRUE; return TRUE;
} }
} }
return result; return FALSE;
} }
static bool get_alt_name_info(struct Curl_easy *data, static bool get_alt_name_info(struct Curl_easy *data,
@ -463,20 +462,19 @@ static bool get_alt_name_info(struct Curl_easy *data,
PCERT_ALT_NAME_INFO *alt_name_info, PCERT_ALT_NAME_INFO *alt_name_info,
LPDWORD alt_name_info_size) LPDWORD alt_name_info_size)
{ {
bool result = FALSE;
PCERT_INFO cert_info = NULL; PCERT_INFO cert_info = NULL;
PCERT_EXTENSION extension = NULL; PCERT_EXTENSION extension = NULL;
CRYPT_DECODE_PARA decode_para = { sizeof(CRYPT_DECODE_PARA), NULL, NULL }; CRYPT_DECODE_PARA decode_para = { sizeof(CRYPT_DECODE_PARA), NULL, NULL };
if(!ctx) { if(!ctx) {
failf(data, "schannel: Null certificate context."); failf(data, "schannel: Null certificate context.");
return result; return FALSE;
} }
cert_info = ctx->pCertInfo; cert_info = ctx->pCertInfo;
if(!cert_info) { if(!cert_info) {
failf(data, "schannel: Null certificate info."); failf(data, "schannel: Null certificate info.");
return result; return FALSE;
} }
extension = CertFindExtension(szOID_SUBJECT_ALT_NAME2, extension = CertFindExtension(szOID_SUBJECT_ALT_NAME2,
@ -484,7 +482,7 @@ static bool get_alt_name_info(struct Curl_easy *data,
cert_info->rgExtension); cert_info->rgExtension);
if(!extension) { if(!extension) {
failf(data, "schannel: CertFindExtension() returned no extension."); failf(data, "schannel: CertFindExtension() returned no extension.");
return result; return FALSE;
} }
if(!CryptDecodeObjectEx(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, if(!CryptDecodeObjectEx(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
@ -496,11 +494,10 @@ static bool get_alt_name_info(struct Curl_easy *data,
alt_name_info, alt_name_info,
alt_name_info_size)) { alt_name_info_size)) {
failf(data, "schannel: CryptDecodeObjectEx() returned no alternate name " failf(data, "schannel: CryptDecodeObjectEx() returned no alternate name "
"information."); "information.");
return result; return FALSE;
} }
result = TRUE; return TRUE;
return result;
} }
/* Verify the server's hostname */ /* Verify the server's hostname */

View file

@ -1455,16 +1455,16 @@ static bool ssl_cf_data_pending(struct Curl_cfilter *cf,
{ {
struct ssl_connect_data *connssl = cf->ctx; struct ssl_connect_data *connssl = cf->ctx;
struct cf_call_data save; struct cf_call_data save;
bool result; bool pending;
CF_DATA_SAVE(save, cf, data); CF_DATA_SAVE(save, cf, data);
if(connssl->ssl_impl->data_pending && if(connssl->ssl_impl->data_pending &&
connssl->ssl_impl->data_pending(cf, data)) connssl->ssl_impl->data_pending(cf, data))
result = TRUE; pending = TRUE;
else else
result = cf->next->cft->has_data_pending(cf->next, data); pending = cf->next->cft->has_data_pending(cf->next, data);
CF_DATA_RESTORE(cf, save); CF_DATA_RESTORE(cf, save);
return result; return pending;
} }
static CURLcode ssl_cf_send(struct Curl_cfilter *cf, static CURLcode ssl_cf_send(struct Curl_cfilter *cf,