From 21e7e44fb9b068258df3ed0daed4f081c3108ebb Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 13 Apr 2023 13:52:08 +0200 Subject: [PATCH] url: fix PVS nits - expression 'hostptr' is always true - a part of conditional expression is always true: proxypasswd - expression 'proxyuser' is always true - avoid multiple Curl_now() calls in allocate_conn Ref: #10929 Closes #10959 --- lib/url.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/lib/url.c b/lib/url.c index 3b24062123..71ca1b64e4 100644 --- a/lib/url.c +++ b/lib/url.c @@ -1510,7 +1510,7 @@ static struct connectdata *allocate_conn(struct Curl_easy *data) conn->created = Curl_now(); /* Store current time to give a baseline to keepalive connection times. */ - conn->keepalive = Curl_now(); + conn->keepalive = conn->created; #ifndef CURL_DISABLE_PROXY conn->http_proxy.proxytype = data->set.proxytype; @@ -1583,7 +1583,7 @@ static struct connectdata *allocate_conn(struct Curl_easy *data) it may live on without (this specific) Curl_easy */ conn->fclosesocket = data->set.fclosesocket; conn->closesocket_client = data->set.closesocket_client; - conn->lastused = Curl_now(); /* used now */ + conn->lastused = conn->created; conn->gssapi_delegation = data->set.gssapi_delegation; return conn; @@ -2328,22 +2328,17 @@ static CURLcode parse_proxy_auth(struct Curl_easy *data, data->state.aptr.proxyuser : ""; const char *proxypasswd = data->state.aptr.proxypasswd ? data->state.aptr.proxypasswd : ""; - CURLcode result = CURLE_OK; - - if(proxyuser) { - result = Curl_urldecode(proxyuser, 0, &conn->http_proxy.user, NULL, - REJECT_ZERO); - if(!result) - result = Curl_setstropt(&data->state.aptr.proxyuser, - conn->http_proxy.user); - } - if(!result && proxypasswd) { + CURLcode result = Curl_urldecode(proxyuser, 0, &conn->http_proxy.user, NULL, + REJECT_ZERO); + if(!result) + result = Curl_setstropt(&data->state.aptr.proxyuser, + conn->http_proxy.user); + if(!result) result = Curl_urldecode(proxypasswd, 0, &conn->http_proxy.passwd, NULL, REJECT_ZERO); - if(!result) - result = Curl_setstropt(&data->state.aptr.proxypasswd, - conn->http_proxy.passwd); - } + if(!result) + result = Curl_setstropt(&data->state.aptr.proxypasswd, + conn->http_proxy.passwd); return result; } @@ -2899,12 +2894,11 @@ static CURLcode parse_connect_to_host_port(struct Curl_easy *data, } /* now, clone the cleaned host name */ - if(hostptr) { - *hostname_result = strdup(hostptr); - if(!*hostname_result) { - result = CURLE_OUT_OF_MEMORY; - goto error; - } + DEBUGASSERT(hostptr); + *hostname_result = strdup(hostptr); + if(!*hostname_result) { + result = CURLE_OUT_OF_MEMORY; + goto error; } *port_result = port; -- 2.47.3