Fixed -Wshorten-64-to-32

pull/13171/head
Esun Kim 5 years ago
parent f3514c0600
commit a8bb192fa4
  1. 17
      upb/decode.c
  2. 4
      upb/table.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);

@ -646,7 +646,7 @@ void upb_inttable_compact2(upb_inttable *t, upb_alloc *a) {
size_t arr_size = max[size_lg2] + 1; /* +1 so arr[max] will fit. */
size_t hash_count = upb_inttable_count(t) - arr_count;
size_t hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0;
size_t hashsize_lg2 = log2ceil(hash_size);
int hashsize_lg2 = log2ceil(hash_size);
upb_inttable_sizedinit(&new_t, t->t.ctype, arr_size, hashsize_lg2, a);
upb_inttable_begin(&i, t);
@ -798,7 +798,7 @@ uint32_t MurmurHash2(const void * key, size_t len, uint32_t seed) {
const uint32_t m = 0x5bd1e995;
const int32_t r = 24;
const uint8_t * data = (const uint8_t *)key;
uint32_t h = seed ^ len;
uint32_t h = (uint32_t)(seed ^ len);
uint8_t align = (uintptr_t)data & 3;
if(align && (len >= 4)) {

Loading…
Cancel
Save