From 913d026e00cb4be1a4f58a2c34ad6cf152e9bb8d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 23 Jan 2015 13:47:56 -0800 Subject: [PATCH 1/3] src --- src/core/support/string.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/support/string.h b/src/core/support/string.h index 71bd3f84e30..2ce4b7f7856 100644 --- a/src/core/support/string.h +++ b/src/core/support/string.h @@ -60,7 +60,7 @@ char *gpr_hexdump(const char *buf, size_t len, gpr_uint32 flags); int gpr_parse_bytes_to_uint32(const char *data, size_t length, gpr_uint32 *result); -/* minimum buffer size for calling ltoa */ +/* Minimum buffer size for calling ltoa */ #define GPR_LTOA_MIN_BUFSIZE (3 * sizeof(long)) /* Convert a long to a string in base 10; returns the length of the From 672cd42a04aa74d86f8ffbc1aa44b662ea7f6f1b Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 23 Jan 2015 13:48:49 -0800 Subject: [PATCH 2/3] Formatting --- src/core/support/string.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/support/string.h b/src/core/support/string.h index 2ce4b7f7856..28b7029ecd6 100644 --- a/src/core/support/string.h +++ b/src/core/support/string.h @@ -64,7 +64,8 @@ int gpr_parse_bytes_to_uint32(const char *data, size_t length, #define GPR_LTOA_MIN_BUFSIZE (3 * sizeof(long)) /* Convert a long to a string in base 10; returns the length of the - output string (or 0 on failure) */ + output string (or 0 on failure). + output must be at least GPR_LTOA_MIN_BUFSIZE bytes long. */ int gpr_ltoa(long value, char *output); /* Reverse a run of bytes */ From b7b9c758ed04a2de87822b5f37a993e529b84c28 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 23 Jan 2015 13:52:43 -0800 Subject: [PATCH 3/3] Add constant for min bufsize for timeout encoding --- src/core/transport/chttp2/timeout_encoding.h | 3 +++ test/core/transport/chttp2/timeout_encoding_test.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/transport/chttp2/timeout_encoding.h b/src/core/transport/chttp2/timeout_encoding.h index a4582566adc..d1e47760324 100644 --- a/src/core/transport/chttp2/timeout_encoding.h +++ b/src/core/transport/chttp2/timeout_encoding.h @@ -34,8 +34,11 @@ #ifndef __GRPC_INTERNAL_TRANSPORT_CHTTP2_TIMEOUT_ENCODING_H_ #define __GRPC_INTERNAL_TRANSPORT_CHTTP2_TIMEOUT_ENCODING_H_ +#include "src/core/support/string.h" #include +#define GRPC_CHTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE (GPR_LTOA_MIN_BUFSIZE + 1) + /* Encode/decode timeouts to the GRPC over HTTP2 format; encoding may round up arbitrarily */ void grpc_chttp2_encode_timeout(gpr_timespec timeout, char *buffer); diff --git a/test/core/transport/chttp2/timeout_encoding_test.c b/test/core/transport/chttp2/timeout_encoding_test.c index 4bb84e3f0bf..ffa0070e341 100644 --- a/test/core/transport/chttp2/timeout_encoding_test.c +++ b/test/core/transport/chttp2/timeout_encoding_test.c @@ -43,7 +43,7 @@ #define LOG_TEST() gpr_log(GPR_INFO, "%s", __FUNCTION__) static void assert_encodes_as(gpr_timespec ts, const char *s) { - char buffer[32]; + char buffer[GRPC_CHTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE]; grpc_chttp2_encode_timeout(ts, buffer); gpr_log(GPR_INFO, "check '%s' == '%s'", buffer, s); GPR_ASSERT(0 == strcmp(buffer, s));