From 8c6d0e5545f116be2f7fad3b5525f4eec01cfbba Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Wed, 7 Mar 2018 17:28:49 +0000 Subject: Conversion from uint64 to uint32 didn't consider sign bit. --- upb/encode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'upb/encode.c') diff --git a/upb/encode.c b/upb/encode.c index a582a2f..f01ad0c 100644 --- a/upb/encode.c +++ b/upb/encode.c @@ -196,9 +196,10 @@ do { ; } while(0) case UPB_DESCRIPTOR_TYPE_UINT64: VARINT_CASE(uint64_t, *ptr); case UPB_DESCRIPTOR_TYPE_UINT32: + VARINT_CASE(uint32_t, *ptr); case UPB_DESCRIPTOR_TYPE_INT32: case UPB_DESCRIPTOR_TYPE_ENUM: - VARINT_CASE(uint32_t, *ptr); + VARINT_CASE(int32_t, (int64_t)*ptr); case UPB_DESCRIPTOR_TYPE_BOOL: VARINT_CASE(bool, *ptr); case UPB_DESCRIPTOR_TYPE_SINT32: @@ -276,9 +277,10 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, case UPB_DESCRIPTOR_TYPE_UINT64: CASE(uint64_t, varint, UPB_WIRE_TYPE_VARINT, val); case UPB_DESCRIPTOR_TYPE_UINT32: + CASE(uint32_t, varint, UPB_WIRE_TYPE_VARINT, val); case UPB_DESCRIPTOR_TYPE_INT32: case UPB_DESCRIPTOR_TYPE_ENUM: - CASE(uint32_t, varint, UPB_WIRE_TYPE_VARINT, val); + CASE(int32_t, varint, UPB_WIRE_TYPE_VARINT, (int64_t)val); case UPB_DESCRIPTOR_TYPE_SFIXED64: case UPB_DESCRIPTOR_TYPE_FIXED64: CASE(uint64_t, fixed64, UPB_WIRE_TYPE_64BIT, val); -- cgit v1.2.3