diff --git a/upb/decode.c b/upb/decode.c index abc3ecb55b..4a54ac0445 100644 --- a/upb/decode.c +++ b/upb/decode.c @@ -278,7 +278,7 @@ static void decode_munge(int type, wireval *val) { val->bool_val = val->uint64_val != 0; break; case UPB_DESCRIPTOR_TYPE_SINT32: { - uint32_t n = val->uint32_val; + uint32_t n = val->uint64_val; val->uint32_val = (n >> 1) ^ -(int32_t)(n & 1); break; } diff --git a/upb/json_decode.c b/upb/json_decode.c index cc8139e455..76232dbd19 100644 --- a/upb/json_decode.c +++ b/upb/json_decode.c @@ -719,7 +719,8 @@ static upb_msgval jsondec_int(jsondec *d, const upb_fielddef *f) { jsondec_err(d, "Expected number or string"); } - if (upb_fielddef_type(f) == UPB_TYPE_INT32) { + if (upb_fielddef_type(f) == UPB_TYPE_INT32 || + upb_fielddef_type(f) == UPB_TYPE_ENUM) { if (val.int64_val > INT32_MAX || val.int64_val < INT32_MIN) { jsondec_err(d, "Integer out of range."); }