diff --git a/src/core/channel/call_op_string.c b/src/core/channel/call_op_string.c index 4f19d021d5e..d36d51e7896 100644 --- a/src/core/channel/call_op_string.c +++ b/src/core/channel/call_op_string.c @@ -117,7 +117,7 @@ char *grpc_call_op_string(grpc_call_op *op) { gpr_asprintf(&tmp, " flags=0x%08x", op->flags); gpr_strvec_add(&b, tmp); - out = gpr_strvec_flatten(&b); + out = gpr_strvec_flatten(&b, NULL); gpr_strvec_destroy(&b); return out; diff --git a/src/core/support/string.c b/src/core/support/string.c index 87c2cd351b0..008b2aac899 100644 --- a/src/core/support/string.c +++ b/src/core/support/string.c @@ -153,7 +153,7 @@ int gpr_ltoa(long value, char *string) { return i; } -char *gpr_strjoin(const char **strs, size_t nstrs) { +char *gpr_strjoin(const char **strs, size_t nstrs, size_t *final_length) { size_t out_length = 0; size_t i; char *out; @@ -169,6 +169,9 @@ char *gpr_strjoin(const char **strs, size_t nstrs) { out_length += slen; } out[out_length] = 0; + if (final_length != NULL) { + *final_length = out_length; + } return out; } @@ -192,6 +195,6 @@ void gpr_strvec_add(gpr_strvec *sv, char *str) { sv->strs[sv->count++] = str; } -char *gpr_strvec_flatten(gpr_strvec *sv) { - return gpr_strjoin((const char**)sv->strs, sv->count); +char *gpr_strvec_flatten(gpr_strvec *sv, size_t *final_length) { + return gpr_strjoin((const char**)sv->strs, sv->count, final_length); } diff --git a/src/core/support/string.h b/src/core/support/string.h index 98c66b14e2d..d8fd2638ef8 100644 --- a/src/core/support/string.h +++ b/src/core/support/string.h @@ -81,8 +81,10 @@ void gpr_reverse_bytes(char *str, int len); the result is undefined. */ int gpr_asprintf(char **strp, const char *format, ...); -/* Join a set of strings, returning the resulting string */ -char *gpr_strjoin(const char **strs, size_t nstrs); +/* Join a set of strings, returning the resulting string. + Total combined length (excluding null terminator) is returned in total_length + if it is non-null. */ +char *gpr_strjoin(const char **strs, size_t nstrs, size_t *total_length); /* A vector of strings... addition takes ownership of strings */ typedef struct { @@ -94,7 +96,7 @@ typedef struct { void gpr_strvec_init(gpr_strvec *strs); void gpr_strvec_destroy(gpr_strvec *strs); void gpr_strvec_add(gpr_strvec *strs, char *add); -char *gpr_strvec_flatten(gpr_strvec *strs); +char *gpr_strvec_flatten(gpr_strvec *strs, size_t *total_length); #ifdef __cplusplus } diff --git a/src/core/surface/event_string.c b/src/core/surface/event_string.c index 5a71cdadaba..8975d312eec 100644 --- a/src/core/surface/event_string.c +++ b/src/core/surface/event_string.c @@ -131,7 +131,7 @@ char *grpc_event_string(grpc_event *ev) { break; } - out = gpr_strvec_flatten(&buf); + out = gpr_strvec_flatten(&buf, NULL); gpr_strvec_destroy(&buf); return out; }