aboutsummaryrefslogtreecommitdiffstats
path: root/test/testutil
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/testutil
parent1a78a33aed6d182bf26a3e839341b9ea38dbcaa3 (diff)
downloadopenssl-4483fbae10a9277812cc8a587ef58a5a512fe7c9.tar.gz
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/testutil')
-rw-r--r--test/testutil/driver.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/testutil/driver.c b/test/testutil/driver.c
index 48593f9201..9cdce7a4e0 100644
--- a/test/testutil/driver.c
+++ b/test/testutil/driver.c
@@ -272,3 +272,28 @@ int run_tests(const char *test_prog_name)
return EXIT_SUCCESS;
}
+/*
+ * Glue an array of strings together and return it as an allocated string.
+ * Optionally return the whole length of this string in |out_len|
+ */
+char *glue_strings(const char *list[], size_t *out_len)
+{
+ size_t len = 0;
+ char *p, *ret;
+ int i;
+
+ for (i = 0; list[i] != NULL; i++)
+ len += strlen(list[i]);
+
+ if (out_len != NULL)
+ *out_len = len;
+
+ if (!TEST_ptr(ret = p = OPENSSL_malloc(len + 1)))
+ return NULL;
+
+ for (i = 0; list[i] != NULL; i++)
+ p += strlen(strcpy(p, list[i]));
+
+ return ret;
+}
+