mirror of
https://github.com/moparisthebest/curl
synced 2024-11-05 17:15:04 -05:00
vtls: Refactor Curl_multissl_version to make the code clearer
Reported-by: Johannes Schindelin Ref: https://github.com/curl/curl/pull/3863#pullrequestreview-241395121 Closes https://github.com/curl/curl/pull/4803
This commit is contained in:
parent
8bd14c871f
commit
c9c551f1f9
@ -1236,7 +1236,7 @@ static size_t Curl_multissl_version(char *buffer, size_t size)
|
||||
{
|
||||
static const struct Curl_ssl *selected;
|
||||
static char backends[200];
|
||||
static size_t total;
|
||||
static size_t backends_len;
|
||||
const struct Curl_ssl *current;
|
||||
|
||||
current = Curl_ssl == &Curl_ssl_multi ? available_backends[0] : Curl_ssl;
|
||||
@ -1248,27 +1248,32 @@ static size_t Curl_multissl_version(char *buffer, size_t size)
|
||||
|
||||
selected = current;
|
||||
|
||||
for(i = 0; available_backends[i] && p < (end - 4); i++) {
|
||||
if(i)
|
||||
*(p++) = ' ';
|
||||
if(selected != available_backends[i])
|
||||
*(p++) = '(';
|
||||
p += available_backends[i]->version(p, end - p - 2);
|
||||
if(selected != available_backends[i])
|
||||
*(p++) = ')';
|
||||
backends[0] = '\0';
|
||||
|
||||
for(i = 0; available_backends[i]; ++i) {
|
||||
char vb[200];
|
||||
bool paren = (selected != available_backends[i]);
|
||||
|
||||
if(available_backends[i]->version(vb, sizeof(vb))) {
|
||||
p += msnprintf(p, end - p, "%s%s%s%s", (p != backends ? " " : ""),
|
||||
(paren ? "(" : ""), vb, (paren ? ")" : ""));
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
total = p - backends;
|
||||
|
||||
backends_len = p - backends;
|
||||
}
|
||||
|
||||
if(size > total)
|
||||
memcpy(buffer, backends, total + 1);
|
||||
else {
|
||||
memcpy(buffer, backends, size - 1);
|
||||
if(!size)
|
||||
return 0;
|
||||
|
||||
if(size <= backends_len) {
|
||||
strncpy(buffer, backends, size - 1);
|
||||
buffer[size - 1] = '\0';
|
||||
return size - 1;
|
||||
}
|
||||
|
||||
return CURLMIN(size - 1, total);
|
||||
strcpy(buffer, backends);
|
||||
return backends_len;
|
||||
}
|
||||
|
||||
static int multissl_init(const struct Curl_ssl *backend)
|
||||
|
Loading…
Reference in New Issue
Block a user