summaryrefslogtreecommitdiffstats
path: root/test/crltest.c
diff options
context:
space:
mode:
authorFdaSilvaYY <fdasilvayy@gmail.com>2017-11-07 11:50:30 +0100
committerRich Salz <rsalz@openssl.org>2017-11-13 07:52:35 -0500
commit4483fbae10a9277812cc8a587ef58a5a512fe7c9 (patch)
treec3879b67351cc43c7e61a671386ca7eeddd90799 /test/crltest.c
parent1a78a33aed6d182bf26a3e839341b9ea38dbcaa3 (diff)
Factorise duplicated code.
Extract and factorise duplicated string glue code. Cache strlen result to avoid duplicate calls. [extended tests] Reviewed-by: Andy Polyakov <appro@openssl.org> Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/4719)
Diffstat (limited to 'test/crltest.c')
-rw-r--r--test/crltest.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/test/crltest.c b/test/crltest.c
index b96463705c..4d35fd4081 100644
--- a/test/crltest.c
+++ b/test/crltest.c
@@ -187,20 +187,11 @@ static X509 *test_leaf = NULL;
* Glue an array of strings together. Return a BIO and put the string
* into |*out| so we can free it.
*/
-static BIO *glue(const char **pem, char **out)
+static BIO *glue2bio(const char **pem, char **out)
{
- char *dest;
- int i;
size_t s = 0;
- /* Glue the strings together. */
- for (i = 0; pem[i] != NULL; ++i)
- s += strlen(pem[i]);
- dest = *out = OPENSSL_malloc(s + 1);
- if (dest == NULL)
- return NULL;
- for (i = 0; pem[i] != NULL; ++i)
- dest += strlen(strcpy(dest, pem[i]));
+ *out = glue_strings(pem, &s);
return BIO_new_mem_buf(*out, s);
}
@@ -210,7 +201,7 @@ static BIO *glue(const char **pem, char **out)
static X509_CRL *CRL_from_strings(const char **pem)
{
char *p;
- BIO *b = glue(pem, &p);
+ BIO *b = glue2bio(pem, &p);
X509_CRL *crl = PEM_read_bio_X509_CRL(b, NULL, NULL, NULL);
OPENSSL_free(p);
@@ -224,7 +215,7 @@ static X509_CRL *CRL_from_strings(const char **pem)
static X509 *X509_from_strings(const char **pem)
{
char *p;
- BIO *b = glue(pem, &p);
+ BIO *b = glue2bio(pem, &p);
X509 *x = PEM_read_bio_X509(b, NULL, NULL, NULL);
OPENSSL_free(p);