mirror of https://github.com/moparisthebest/curl
simplied how create_hostcache_id() is used, and also its function somewhat
cleared up some ssize_t/size_t mixups
This commit is contained in:
parent
f493081004
commit
35fd1365ae
26
lib/hostip.c
26
lib/hostip.c
|
@ -156,30 +156,24 @@ static int _num_chars(int i)
|
||||||
|
|
||||||
/* Create a hostcache id */
|
/* Create a hostcache id */
|
||||||
static char *
|
static char *
|
||||||
create_hostcache_id(char *server, int port, ssize_t *entry_len)
|
create_hostcache_id(char *server, int port, size_t *entry_len)
|
||||||
{
|
{
|
||||||
char *id = NULL;
|
char *id = NULL;
|
||||||
|
|
||||||
/* Get the length of the new entry id */
|
/* Get the length of the new entry id */
|
||||||
*entry_len = *entry_len + /* Hostname length */
|
*entry_len = strlen(server) + /* Hostname length */
|
||||||
1 + /* ':' seperator */
|
1 + /* ':' seperator */
|
||||||
_num_chars(port); /* number of characters the port will take up */
|
_num_chars(port); /* number of characters the port will take up */
|
||||||
|
|
||||||
/* Allocate the new entry id */
|
/* Allocate the new entry id */
|
||||||
id = malloc(*entry_len + 1);
|
id = malloc(*entry_len + 1); /* 1 extra for the zero terminator */
|
||||||
if (!id)
|
if (!id)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Create the new entry */
|
/* Create the new entry */
|
||||||
/* If sprintf() doesn't return the entry length, that signals failure */
|
sprintf(id, "%s:%d", server, port);
|
||||||
if (sprintf(id, "%s:%d", server, port) != *entry_len) {
|
|
||||||
/* Free the allocated id, set length to zero and return NULL */
|
|
||||||
*entry_len = 0;
|
|
||||||
free(id);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return id;
|
return id; /* return pointer to the string */
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hostcache_prune_data {
|
struct hostcache_prune_data {
|
||||||
|
@ -256,12 +250,11 @@ cache_resolv_response(struct SessionHandle *data,
|
||||||
int port)
|
int port)
|
||||||
{
|
{
|
||||||
char *entry_id;
|
char *entry_id;
|
||||||
ssize_t entry_len;
|
size_t entry_len;
|
||||||
struct Curl_dns_entry *dns;
|
struct Curl_dns_entry *dns;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
/* Create an entry id, based upon the hostname and port */
|
/* Create an entry id, based upon the hostname and port */
|
||||||
entry_len = strlen(hostname);
|
|
||||||
entry_id = create_hostcache_id(hostname, port, &entry_len);
|
entry_id = create_hostcache_id(hostname, port, &entry_len);
|
||||||
/* If we can't create the entry id, fail */
|
/* If we can't create the entry id, fail */
|
||||||
if (!entry_id)
|
if (!entry_id)
|
||||||
|
@ -315,7 +308,7 @@ int Curl_resolv(struct connectdata *conn,
|
||||||
{
|
{
|
||||||
char *entry_id = NULL;
|
char *entry_id = NULL;
|
||||||
struct Curl_dns_entry *dns = NULL;
|
struct Curl_dns_entry *dns = NULL;
|
||||||
ssize_t entry_len;
|
size_t entry_len;
|
||||||
int wait;
|
int wait;
|
||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
CURLcode result;
|
CURLcode result;
|
||||||
|
@ -335,7 +328,6 @@ int Curl_resolv(struct connectdata *conn,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Create an entry id, based upon the hostname and port */
|
/* Create an entry id, based upon the hostname and port */
|
||||||
entry_len = strlen(hostname);
|
|
||||||
entry_id = create_hostcache_id(hostname, port, &entry_len);
|
entry_id = create_hostcache_id(hostname, port, &entry_len);
|
||||||
/* If we can't create the entry id, fail */
|
/* If we can't create the entry id, fail */
|
||||||
if (!entry_id)
|
if (!entry_id)
|
||||||
|
|
Loading…
Reference in New Issue