From 247bb9eb7e38f3ee5612a6be8fe2dc1675b87d33 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 19 Jun 2015 12:25:14 -0700 Subject: [PATCH 1/2] Fixed conversion warnings in src/core/json --- src/core/json/json_reader.c | 12 ++++++------ src/core/json/json_string.c | 22 +++++++++++----------- src/core/json/json_writer.c | 14 +++++++------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/core/json/json_reader.c b/src/core/json/json_reader.c index 5ea4e9569c0..c14094c290a 100644 --- a/src/core/json/json_reader.c +++ b/src/core/json/json_reader.c @@ -151,7 +151,7 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { case GRPC_JSON_STATE_VALUE_NUMBER_WITH_DECIMAL: case GRPC_JSON_STATE_VALUE_NUMBER_ZERO: case GRPC_JSON_STATE_VALUE_NUMBER_EPM: - success = json_reader_set_number(reader); + success = (gpr_uint32)json_reader_set_number(reader); if (!success) return GRPC_JSON_PARSE_ERROR; json_reader_string_clear(reader); reader->state = GRPC_JSON_STATE_VALUE_END; @@ -177,7 +177,7 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { case GRPC_JSON_STATE_VALUE_NUMBER_WITH_DECIMAL: case GRPC_JSON_STATE_VALUE_NUMBER_ZERO: case GRPC_JSON_STATE_VALUE_NUMBER_EPM: - success = json_reader_set_number(reader); + success = (gpr_uint32)json_reader_set_number(reader); if (!success) return GRPC_JSON_PARSE_ERROR; json_reader_string_clear(reader); reader->state = GRPC_JSON_STATE_VALUE_END; @@ -410,8 +410,8 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { } else { return GRPC_JSON_PARSE_ERROR; } - reader->unicode_char <<= 4; - reader->unicode_char |= c; + reader->unicode_char = (gpr_uint16)(reader->unicode_char << 4); + reader->unicode_char = (gpr_uint16)(reader->unicode_char | c); switch (reader->state) { case GRPC_JSON_STATE_STRING_ESCAPE_U1: @@ -438,8 +438,8 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader) { if (reader->unicode_high_surrogate == 0) return GRPC_JSON_PARSE_ERROR; utf32 = 0x10000; - utf32 += (reader->unicode_high_surrogate - 0xd800) * 0x400; - utf32 += reader->unicode_char - 0xdc00; + utf32 += (gpr_uint32)((reader->unicode_high_surrogate - 0xd800) * 0x400); + utf32 += (gpr_uint32)(reader->unicode_char - 0xdc00); json_reader_string_add_utf32(reader, utf32); reader->unicode_high_surrogate = 0; } else { diff --git a/src/core/json/json_string.c b/src/core/json/json_string.c index 13f816995b2..785ec50411e 100644 --- a/src/core/json/json_string.c +++ b/src/core/json/json_string.c @@ -83,7 +83,7 @@ static void json_writer_output_check(void* userdata, size_t needed) { if (state->free_space >= needed) return; needed -= state->free_space; /* Round up by 256 bytes. */ - needed = (needed + 0xff) & ~0xff; + needed = (needed + 0xff) % 0x100; state->output = gpr_realloc(state->output, state->allocated + needed); state->free_space += needed; state->allocated += needed; @@ -128,7 +128,7 @@ static void json_reader_string_add_char(void* userdata, gpr_uint32 c) { json_reader_userdata* state = userdata; GPR_ASSERT(state->string_ptr < state->input); GPR_ASSERT(c <= 0xff); - *state->string_ptr++ = (char)c; + *state->string_ptr++ = (gpr_uint8)c; } /* We are converting a UTF-32 character into UTF-8 here, @@ -138,22 +138,22 @@ static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) { if (c <= 0x7f) { json_reader_string_add_char(userdata, c); } else if (c <= 0x7ff) { - int b1 = 0xc0 | ((c >> 6) & 0x1f); - int b2 = 0x80 | (c & 0x3f); + gpr_uint32 b1 = 0xc0 | ((c >> 6) & 0x1f); + gpr_uint32 b2 = 0x80 | (c & 0x3f); json_reader_string_add_char(userdata, b1); json_reader_string_add_char(userdata, b2); } else if (c <= 0xffff) { - int b1 = 0xe0 | ((c >> 12) & 0x0f); - int b2 = 0x80 | ((c >> 6) & 0x3f); - int b3 = 0x80 | (c & 0x3f); + gpr_uint32 b1 = 0xe0 | ((c >> 12) & 0x0f); + gpr_uint32 b2 = 0x80 | ((c >> 6) & 0x3f); + gpr_uint32 b3 = 0x80 | (c & 0x3f); json_reader_string_add_char(userdata, b1); json_reader_string_add_char(userdata, b2); json_reader_string_add_char(userdata, b3); } else if (c <= 0x1fffff) { - int b1 = 0xf0 | ((c >> 18) & 0x07); - int b2 = 0x80 | ((c >> 12) & 0x3f); - int b3 = 0x80 | ((c >> 6) & 0x3f); - int b4 = 0x80 | (c & 0x3f); + gpr_uint32 b1 = 0xf0 | ((c >> 18) & 0x07); + gpr_uint32 b2 = 0x80 | ((c >> 12) & 0x3f); + gpr_uint32 b3 = 0x80 | ((c >> 6) & 0x3f); + gpr_uint32 b4 = 0x80 | (c & 0x3f); json_reader_string_add_char(userdata, b1); json_reader_string_add_char(userdata, b2); json_reader_string_add_char(userdata, b3); diff --git a/src/core/json/json_writer.c b/src/core/json/json_writer.c index a40bf1733e6..bed9a9bfa5a 100644 --- a/src/core/json/json_writer.c +++ b/src/core/json/json_writer.c @@ -66,7 +66,7 @@ static void json_writer_output_indent( " " " "; - unsigned spaces = writer->depth * writer->indent; + unsigned spaces = (unsigned)(writer->depth * writer->indent); if (writer->indent == 0) return; @@ -78,7 +78,7 @@ static void json_writer_output_indent( while (spaces >= (sizeof(spacesstr) - 1)) { json_writer_output_string_with_len(writer, spacesstr, sizeof(spacesstr) - 1); - spaces -= (sizeof(spacesstr) - 1); + spaces -= (unsigned)(sizeof(spacesstr) - 1); } if (spaces == 0) return; @@ -119,7 +119,7 @@ static void json_writer_escape_string(grpc_json_writer* writer, break; } else if ((c >= 32) && (c <= 126)) { if ((c == '\\') || (c == '"')) json_writer_output_char(writer, '\\'); - json_writer_output_char(writer, c); + json_writer_output_char(writer, (char)c); } else if ((c < 32) || (c == 127)) { switch (c) { case '\b': @@ -160,7 +160,7 @@ static void json_writer_escape_string(grpc_json_writer* writer, } for (i = 0; i < extra; i++) { utf32 <<= 6; - c = *string++; + c = (gpr_uint8)(*string++); /* Breaks out and bail on any invalid UTF-8 sequence, including \0. */ if ((c & 0xc0) != 0x80) { valid = 0; @@ -193,10 +193,10 @@ static void json_writer_escape_string(grpc_json_writer* writer, * That range is exactly 20 bits. */ utf32 -= 0x10000; - json_writer_escape_utf16(writer, 0xd800 | (utf32 >> 10)); - json_writer_escape_utf16(writer, 0xdc00 | (utf32 & 0x3ff)); + json_writer_escape_utf16(writer, (gpr_uint16)(0xd800 | (utf32 >> 10))); + json_writer_escape_utf16(writer, (gpr_uint16)(0xdc00 | (utf32 & 0x3ff))); } else { - json_writer_escape_utf16(writer, utf32); + json_writer_escape_utf16(writer, (gpr_uint16)utf32); } } } From 482a44cb5af1ce72d3a56216bc2ea06160cb7bd7 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 19 Jun 2015 16:12:22 -0700 Subject: [PATCH 2/2] Fixed incorrect functional change --- src/core/json/json_string.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/json/json_string.c b/src/core/json/json_string.c index 785ec50411e..03c1099167e 100644 --- a/src/core/json/json_string.c +++ b/src/core/json/json_string.c @@ -83,7 +83,7 @@ static void json_writer_output_check(void* userdata, size_t needed) { if (state->free_space >= needed) return; needed -= state->free_space; /* Round up by 256 bytes. */ - needed = (needed + 0xff) % 0x100; + needed = (needed + 0xff) & ~0xffU; state->output = gpr_realloc(state->output, state->allocated + needed); state->free_space += needed; state->allocated += needed;