Merge pull request #2142 from murgatroid99/core_json_conversion_warnings

Fixed integer conversion warnings in src/core/json
pull/2173/head
Nicolas Noble 10 years ago
commit 1d7683d13f
  1. 12
      src/core/json/json_reader.c
  2. 22
      src/core/json/json_string.c
  3. 14
      src/core/json/json_writer.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 {

@ -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) & ~0xffU;
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);

@ -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);
}
}
}

Loading…
Cancel
Save