From 7673f7ac63d8bf7e18bdcd2888c5c57822ce938f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 18 Apr 2016 22:44:57 -0700 Subject: Change string format --- test/core/end2end/fuzzers/api_fuzzer.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'test/core') diff --git a/test/core/end2end/fuzzers/api_fuzzer.c b/test/core/end2end/fuzzers/api_fuzzer.c index 9f11e750c7..a914482588 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.c +++ b/test/core/end2end/fuzzers/api_fuzzer.c @@ -73,12 +73,18 @@ static uint8_t next_byte(input_stream *inp) { static void end(input_stream *inp) { inp->cur = inp->end; } static char *read_string(input_stream *inp) { - size_t len = next_byte(inp); - char *str = gpr_malloc(len + 1); - for (size_t i = 0; i < len; i++) { - str[i] = (char)next_byte(inp); - } - str[len] = 0; + char *str = NULL; + size_t cap = 0; + size_t sz = 0; + char c; + do { + if (cap == sz) { + cap = GPR_MAX(3*cap/2, cap+8); + str = gpr_realloc(str, cap); + } + c = (char)next_byte(inp); + str[sz++] = c; + } while (c != 0); return str; } -- cgit v1.2.3