1 #include "utils.h" 2 3 #include <stdlib.h> 4 #include <string.h> 5 generate_test_sarray(size_t len)6char** generate_test_sarray(size_t len) 7 { 8 static const char testString[] = "test"; 9 size_t i; 10 char** ret = calloc(len + 1, sizeof(*ret)); 11 if (!ret) 12 { 13 return NULL; 14 } 15 16 for (i = 0; i < len; ++i) 17 { 18 ret[i] = strdup(testString); 19 if (!ret[i]) 20 { 21 goto error; 22 } 23 } 24 25 return ret; 26 27 error: 28 for (i = 0; i < len; ++i) 29 { 30 free(ret[i]); 31 } 32 free(ret); 33 34 return NULL; 35 } 36