From 4483fbae10a9277812cc8a587ef58a5a512fe7c9 Mon Sep 17 00:00:00 2001 From: FdaSilvaYY Date: Tue, 7 Nov 2017 11:50:30 +0100 Subject: Factorise duplicated code. Extract and factorise duplicated string glue code. Cache strlen result to avoid duplicate calls. [extended tests] Reviewed-by: Andy Polyakov Reviewed-by: Rich Salz (Merged from https://github.com/openssl/openssl/pull/4719) --- test/testutil/driver.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/testutil') 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; +} + -- cgit v1.2.3