From a8bb192fa4158413495a64a146a1ca0cd8b9df07 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Wed, 31 Jul 2019 09:11:34 -0700 Subject: Fixed -Wshorten-64-to-32 --- upb/decode.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'upb/decode.c') diff --git a/upb/decode.c b/upb/decode.c index 5ba1f05..88d4bb4 100644 --- a/upb/decode.c +++ b/upb/decode.c @@ -74,7 +74,7 @@ static bool upb_decode_varint32(const char **ptr, const char *limit, uint32_t *val) { uint64_t u64; CHK(upb_decode_varint(ptr, limit, &u64) && u64 <= UINT32_MAX); - *val = u64; + *val = (uint32_t)u64; return true; } @@ -336,7 +336,7 @@ static bool upb_decode_varintfield(upb_decstate *d, upb_decframe *frame, case UPB_DESCRIPTOR_TYPE_INT32: case UPB_DESCRIPTOR_TYPE_UINT32: case UPB_DESCRIPTOR_TYPE_ENUM: { - uint32_t val32 = val; + uint32_t val32 = (uint32_t)val; CHK(upb_decode_addval(frame, field, &val32, sizeof(val32))); break; } @@ -346,7 +346,7 @@ static bool upb_decode_varintfield(upb_decstate *d, upb_decframe *frame, break; } case UPB_DESCRIPTOR_TYPE_SINT32: { - int32_t decoded = upb_zzdecode_32(val); + int32_t decoded = upb_zzdecode_32((uint32_t)val); CHK(upb_decode_addval(frame, field, &decoded, sizeof(decoded))); break; } @@ -425,7 +425,10 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame, upb_array *arr = upb_getorcreatearr(frame, field); CHK(arr); -#define VARINT_CASE(ctype, decode) \ +#define VARINT_CASE(ctype, decode) \ + VARINT_CASE_EX(ctype, decode, decode) + +#define VARINT_CASE_EX(ctype, decode, dtype) \ { \ const char *ptr = d->ptr; \ const char *limit = ptr + len; \ @@ -433,7 +436,7 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame, uint64_t val; \ ctype decoded; \ CHK(upb_decode_varint(&ptr, limit, &val)); \ - decoded = (decode)(val); \ + decoded = (decode)((dtype)val); \ CHK(upb_array_add(arr, 1, sizeof(decoded), &decoded, d->arena)); \ } \ d->ptr = ptr; \ @@ -464,9 +467,9 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame, case UPB_DESCRIPTOR_TYPE_BOOL: VARINT_CASE(bool, bool); case UPB_DESCRIPTOR_TYPE_SINT32: - VARINT_CASE(int32_t, upb_zzdecode_32); + VARINT_CASE_EX(int32_t, upb_zzdecode_32, uint32_t); case UPB_DESCRIPTOR_TYPE_SINT64: - VARINT_CASE(int64_t, upb_zzdecode_64); + VARINT_CASE_EX(int64_t, upb_zzdecode_64, uint64_t); case UPB_DESCRIPTOR_TYPE_MESSAGE: { const upb_msglayout *subm; upb_msg *submsg = upb_addmsg(frame, field, &subm); -- cgit v1.2.3