mirror of
https://github.com/curl/curl.git
synced 2025-09-16 09:02:40 +03:00
http: skip a double NULL assign
and also use a local variable to shorten the long names and increase readability in the function. Pointed out by PVS. Ref: #10929 Closes #10950
This commit is contained in:
parent
51b615a3eb
commit
8b8d7acc6e
30
lib/http.c
30
lib/http.c
|
@ -2163,6 +2163,7 @@ CURLcode Curl_http_useragent(struct Curl_easy *data)
|
||||||
CURLcode Curl_http_host(struct Curl_easy *data, struct connectdata *conn)
|
CURLcode Curl_http_host(struct Curl_easy *data, struct connectdata *conn)
|
||||||
{
|
{
|
||||||
const char *ptr;
|
const char *ptr;
|
||||||
|
struct dynamically_allocated_data *aptr = &data->state.aptr;
|
||||||
if(!data->state.this_is_a_follow) {
|
if(!data->state.this_is_a_follow) {
|
||||||
/* Free to avoid leaking memory on multiple requests */
|
/* Free to avoid leaking memory on multiple requests */
|
||||||
free(data->state.first_host);
|
free(data->state.first_host);
|
||||||
|
@ -2174,7 +2175,7 @@ CURLcode Curl_http_host(struct Curl_easy *data, struct connectdata *conn)
|
||||||
data->state.first_remote_port = conn->remote_port;
|
data->state.first_remote_port = conn->remote_port;
|
||||||
data->state.first_remote_protocol = conn->handler->protocol;
|
data->state.first_remote_protocol = conn->handler->protocol;
|
||||||
}
|
}
|
||||||
Curl_safefree(data->state.aptr.host);
|
Curl_safefree(aptr->host);
|
||||||
|
|
||||||
ptr = Curl_checkheaders(data, STRCONST("Host"));
|
ptr = Curl_checkheaders(data, STRCONST("Host"));
|
||||||
if(ptr && (!data->state.this_is_a_follow ||
|
if(ptr && (!data->state.this_is_a_follow ||
|
||||||
|
@ -2209,19 +2210,16 @@ CURLcode Curl_http_host(struct Curl_easy *data, struct connectdata *conn)
|
||||||
if(colon)
|
if(colon)
|
||||||
*colon = 0; /* The host must not include an embedded port number */
|
*colon = 0; /* The host must not include an embedded port number */
|
||||||
}
|
}
|
||||||
Curl_safefree(data->state.aptr.cookiehost);
|
Curl_safefree(aptr->cookiehost);
|
||||||
data->state.aptr.cookiehost = cookiehost;
|
aptr->cookiehost = cookiehost;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(strcmp("Host:", ptr)) {
|
if(strcmp("Host:", ptr)) {
|
||||||
data->state.aptr.host = aprintf("Host:%s\r\n", &ptr[5]);
|
aptr->host = aprintf("Host:%s\r\n", &ptr[5]);
|
||||||
if(!data->state.aptr.host)
|
if(!aptr->host)
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
/* when clearing the header */
|
|
||||||
data->state.aptr.host = NULL;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* When building Host: headers, we must put the host name within
|
/* When building Host: headers, we must put the host name within
|
||||||
|
@ -2234,18 +2232,14 @@ CURLcode Curl_http_host(struct Curl_easy *data, struct connectdata *conn)
|
||||||
(conn->remote_port == PORT_HTTP)) )
|
(conn->remote_port == PORT_HTTP)) )
|
||||||
/* if(HTTPS on port 443) OR (HTTP on port 80) then don't include
|
/* if(HTTPS on port 443) OR (HTTP on port 80) then don't include
|
||||||
the port number in the host string */
|
the port number in the host string */
|
||||||
data->state.aptr.host = aprintf("Host: %s%s%s\r\n",
|
aptr->host = aprintf("Host: %s%s%s\r\n", conn->bits.ipv6_ip?"[":"",
|
||||||
conn->bits.ipv6_ip?"[":"",
|
host, conn->bits.ipv6_ip?"]":"");
|
||||||
host,
|
|
||||||
conn->bits.ipv6_ip?"]":"");
|
|
||||||
else
|
else
|
||||||
data->state.aptr.host = aprintf("Host: %s%s%s:%d\r\n",
|
aptr->host = aprintf("Host: %s%s%s:%d\r\n", conn->bits.ipv6_ip?"[":"",
|
||||||
conn->bits.ipv6_ip?"[":"",
|
host, conn->bits.ipv6_ip?"]":"",
|
||||||
host,
|
conn->remote_port);
|
||||||
conn->bits.ipv6_ip?"]":"",
|
|
||||||
conn->remote_port);
|
|
||||||
|
|
||||||
if(!data->state.aptr.host)
|
if(!aptr->host)
|
||||||
/* without Host: we can't make a nice request */
|
/* without Host: we can't make a nice request */
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user