Skip to content
Permalink
Browse files

vtls: Refactor Curl_multissl_version to make the code clearer

Reported-by: Johannes Schindelin

Ref: #3863 (review)

Closes #4803
  • Loading branch information
jay committed Jan 10, 2020
1 parent 8bd14c8 commit c9c551f1f9a46c3087122e5786cceff72896dac5
Showing with 21 additions and 16 deletions.
  1. +21 −16 lib/vtls/vtls.c
@@ -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)

0 comments on commit c9c551f

Please sign in to comment.
You can’t perform that action at this time.