diff --git a/generated_for_cmake/upb/json/parser.c b/generated_for_cmake/upb/json/parser.c index e3f4d0a465..03087845d5 100644 --- a/generated_for_cmake/upb/json/parser.c +++ b/generated_for_cmake/upb/json/parser.c @@ -970,7 +970,7 @@ static bool parse_number_from_buffer(upb_json_parser *p, const char *buf, } else if (val > INT32_MAX || val < INT32_MIN) { return false; } else { - upb_sink_putint32(p->top->sink, parser_getsel(p), val); + upb_sink_putint32(p->top->sink, parser_getsel(p), (int32_t)val); return true; } } @@ -981,7 +981,7 @@ static bool parse_number_from_buffer(upb_json_parser *p, const char *buf, } else if (val > UINT32_MAX || errno == ERANGE) { return false; } else { - upb_sink_putuint32(p->top->sink, parser_getsel(p), val); + upb_sink_putuint32(p->top->sink, parser_getsel(p), (uint32_t)val); return true; } } diff --git a/tests/pb/test_varint.c b/tests/pb/test_varint.c index cdae9dba47..45d8e47dcd 100644 --- a/tests/pb/test_varint.c +++ b/tests/pb/test_varint.c @@ -16,7 +16,7 @@ static void test_varint_for_num(upb_decoderet (*decoder)(const char*), bytes = upb_vencode64(num, buf); if (num <= UINT32_MAX) { - uint64_t encoded = upb_vencode32(num); + uint64_t encoded = upb_vencode32((uint32_t)num); char buf2[16]; upb_decoderet r; @@ -44,7 +44,7 @@ static void test_varint_for_num(upb_decoderet (*decoder)(const char*), r = decoder(buf2); ASSERT(r.val == num); ASSERT(r.p == buf2 + upb_value_size(encoded)); - ASSERT(upb_zzenc_32(upb_zzdec_32(num)) == num); + ASSERT(upb_zzenc_32(upb_zzdec_32((uint32_t)num)) == num); } r = decoder(buf); diff --git a/upb/def.c b/upb/def.c index fb65689525..f1b477bdc9 100644 --- a/upb/def.c +++ b/upb/def.c @@ -359,7 +359,7 @@ int32_t upb_enumdef_default(const upb_enumdef *e) { } int upb_enumdef_numvals(const upb_enumdef *e) { - return upb_strtable_count(&e->ntoi); + return (int)upb_strtable_count(&e->ntoi); } void upb_enum_begin(upb_enum_iter *i, const upb_enumdef *e) { @@ -496,7 +496,7 @@ int64_t upb_fielddef_defaultint64(const upb_fielddef *f) { int32_t upb_fielddef_defaultint32(const upb_fielddef *f) { chkdefaulttype(f, UPB_TYPE_INT32); - return f->defaultval.sint; + return (int32_t)f->defaultval.sint; } uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f) { @@ -506,7 +506,7 @@ uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f) { uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f) { chkdefaulttype(f, UPB_TYPE_UINT32); - return f->defaultval.uint; + return (uint32_t)f->defaultval.uint; } bool upb_fielddef_defaultbool(const upb_fielddef *f) { @@ -778,7 +778,7 @@ const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o) { } int upb_oneofdef_numfields(const upb_oneofdef *o) { - return upb_strtable_count(&o->ntof); + return (int)upb_strtable_count(&o->ntof); } uint32_t upb_oneofdef_index(const upb_oneofdef *o) { @@ -868,8 +868,8 @@ static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) { } } -static size_t upb_msglayout_place(upb_msglayout *l, size_t size) { - size_t ret; +static uint32_t upb_msglayout_place(upb_msglayout *l, size_t size) { + uint32_t ret; l->size = align_up(l->size, size); ret = l->size; @@ -1994,7 +1994,7 @@ const upb_filedef *upb_symtab_lookupfile(const upb_symtab *s, const char *name) } int upb_symtab_filecount(const upb_symtab *s) { - return upb_strtable_count(&s->files); + return (int)upb_strtable_count(&s->files); } static const upb_filedef *_upb_symtab_addfile( diff --git a/upb/handlers.c b/upb/handlers.c index 844a360176..5cf7ccc074 100644 --- a/upb/handlers.c +++ b/upb/handlers.c @@ -180,7 +180,8 @@ static upb_handlers *upb_handlers_new(const upb_msgdef *md, int extra; upb_handlers *h; - extra = sizeof(upb_handlers_tabent) * (upb_msgdef_selectorcount(md) - 1); + extra = + (int)(sizeof(upb_handlers_tabent) * (upb_msgdef_selectorcount(md) - 1)); h = upb_calloc(arena, sizeof(*h) + extra); if (!h) return NULL; diff --git a/upb/json/parser.rl b/upb/json/parser.rl index 0b303142e7..19022df298 100644 --- a/upb/json/parser.rl +++ b/upb/json/parser.rl @@ -968,7 +968,7 @@ static bool parse_number_from_buffer(upb_json_parser *p, const char *buf, } else if (val > INT32_MAX || val < INT32_MIN) { return false; } else { - upb_sink_putint32(p->top->sink, parser_getsel(p), val); + upb_sink_putint32(p->top->sink, parser_getsel(p), (int32_t)val); return true; } } @@ -979,7 +979,7 @@ static bool parse_number_from_buffer(upb_json_parser *p, const char *buf, } else if (val > UINT32_MAX || errno == ERANGE) { return false; } else { - upb_sink_putuint32(p->top->sink, parser_getsel(p), val); + upb_sink_putuint32(p->top->sink, parser_getsel(p), (uint32_t)val); return true; } } diff --git a/upb/json/printer.c b/upb/json/printer.c index 99b62b2ae2..b0030e0e52 100644 --- a/upb/json/printer.c +++ b/upb/json/printer.c @@ -85,7 +85,7 @@ strpc *newstrpc_str(upb_handlers *h, const char * str) { /* ------------ JSON string printing: values, maps, arrays ------------------ */ static void print_data( - upb_json_printer *p, const char *buf, unsigned int len) { + upb_json_printer *p, const char *buf, size_t len) { /* TODO: Will need to change if we support pushback from the sink. */ size_t n = upb_bytessink_putbuf(p->output_, p->subc_, buf, len, NULL); UPB_ASSERT(n == len); @@ -125,7 +125,7 @@ UPB_INLINE const char* json_nice_escape(char c) { /* Write a properly escaped string chunk. The surrounding quotes are *not* * printed; this is so that the caller has the option of emitting the string * content in chunks. */ -static void putstring(upb_json_printer *p, const char *buf, unsigned int len) { +static void putstring(upb_json_printer *p, const char *buf, size_t len) { const char* unescaped_run = NULL; unsigned int i; for (i = 0; i < len; i++) { diff --git a/upb/msg.c b/upb/msg.c index 6c6d3008aa..8df9d7a1f7 100644 --- a/upb/msg.c +++ b/upb/msg.c @@ -9,7 +9,7 @@ /** upb_msg *******************************************************************/ -static char _upb_fieldtype_to_sizelg2[12] = { +static const char _upb_fieldtype_to_sizelg2[12] = { 0, 0, /* UPB_TYPE_BOOL */ 2, /* UPB_TYPE_FLOAT */ diff --git a/upb/pb/compile_decoder.c b/upb/pb/compile_decoder.c index 44b310fe3f..454397bd1f 100644 --- a/upb/pb/compile_decoder.c +++ b/upb/pb/compile_decoder.c @@ -156,7 +156,9 @@ static void setofs(uint32_t *instruction, int32_t ofs) { UPB_ASSERT(getofs(*instruction) == ofs); /* Would fail in cases of overflow. */ } -static uint32_t pcofs(compiler *c) { return c->pc - c->group->bytecode; } +static uint32_t pcofs(compiler *c) { + return (uint32_t)(c->pc - c->group->bytecode); +} /* Defines a local label at the current PC location. All previous forward * references are updated to point to this location. The location is noted @@ -170,7 +172,7 @@ static void label(compiler *c, unsigned int label) { codep = (val == EMPTYLABEL) ? NULL : c->group->bytecode + val; while (codep) { int ofs = getofs(*codep); - setofs(codep, c->pc - codep - instruction_len(*codep)); + setofs(codep, (int32_t)(c->pc - codep - instruction_len(*codep))); codep = ofs ? codep + ofs : NULL; } c->fwd_labels[label] = EMPTYLABEL; @@ -192,7 +194,7 @@ static int32_t labelref(compiler *c, int label) { return 0; } else if (label < 0) { /* Backward local label. Relative to the next instruction. */ - uint32_t from = (c->pc + 1) - c->group->bytecode; + uint32_t from = (uint32_t)((c->pc + 1) - c->group->bytecode); return c->back_labels[-label] - from; } else { /* Forward local label: prepend to (possibly-empty) linked list. */ @@ -226,7 +228,7 @@ static void putop(compiler *c, int op, ...) { case OP_SETDISPATCH: { uintptr_t ptr = (uintptr_t)va_arg(ap, void*); put32(c, OP_SETDISPATCH); - put32(c, ptr); + put32(c, (uint32_t)ptr); if (sizeof(uintptr_t) > sizeof(uint32_t)) put32(c, (uint64_t)ptr >> 32); break; @@ -285,7 +287,7 @@ static void putop(compiler *c, int op, ...) { case OP_TAG2: { int label = va_arg(ap, int); uint64_t tag = va_arg(ap, uint64_t); - uint32_t instruction = op | (tag << 16); + uint32_t instruction = (uint32_t)(op | (tag << 16)); UPB_ASSERT(tag <= 0xffff); setofs(&instruction, labelref(c, label)); put32(c, instruction); @@ -297,7 +299,7 @@ static void putop(compiler *c, int op, ...) { uint32_t instruction = op | (upb_value_size(tag) << 16); setofs(&instruction, labelref(c, label)); put32(c, instruction); - put32(c, tag); + put32(c, (uint32_t)tag); put32(c, tag >> 32); break; } diff --git a/upb/pb/decoder.c b/upb/pb/decoder.c index ba2b770098..8cdb234526 100644 --- a/upb/pb/decoder.c +++ b/upb/pb/decoder.c @@ -185,7 +185,7 @@ static int32_t skip(upb_pbdecoder *d, size_t bytes) { UPB_ASSERT(d->skip == 0); if (bytes > delim_remaining(d)) { seterr(d, "Skipped value extended beyond enclosing submessage."); - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } else if (bufleft(d) >= bytes) { /* Skipped data is all in current buffer, and more is still available. */ advance(d, bytes); @@ -198,7 +198,7 @@ static int32_t skip(upb_pbdecoder *d, size_t bytes) { d->bufstart_ofs += (d->end - d->buf); d->residual_end = d->residual; switchtobuf(d, d->residual, d->residual_end); - return d->size_param + d->skip; + return (int32_t)(d->size_param + d->skip); } } @@ -238,7 +238,7 @@ int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf, /* NULL buf is ok if its entire span is covered by the "skip" above, but * by this point we know that "skip" doesn't cover the buffer. */ seterr(d, "Passed NULL buffer over non-skippable region."); - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } if (d->residual_end > d->residual) { @@ -348,9 +348,9 @@ UPB_NOINLINE static int32_t getbytes_slow(upb_pbdecoder *d, void *buf, return DECODE_OK; } else if (d->data_end == d->delim_end) { seterr(d, "Submessage ended in the middle of a value or group"); - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } else { - return suspend_save(d); + return (int32_t)suspend_save(d); } } @@ -406,7 +406,7 @@ UPB_NOINLINE int32_t upb_pbdecoder_decode_varint_slow(upb_pbdecoder *d, } if(bitpos == 70 && (byte & 0x80)) { seterr(d, kUnterminatedVarint); - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } return DECODE_OK; } @@ -423,7 +423,7 @@ UPB_FORCEINLINE static int32_t decode_varint(upb_pbdecoder *d, uint64_t *u64) { upb_decoderet r = upb_vdecode_fast(d->ptr); if (r.p == NULL) { seterr(d, kUnterminatedVarint); - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } advance(d, r.p - d->ptr); *u64 = r.val; @@ -447,9 +447,9 @@ UPB_FORCEINLINE static int32_t decode_v32(upb_pbdecoder *d, uint32_t *u32) { * Right now the size_t -> int32_t can overflow and produce negative values. */ *u32 = 0; - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } - *u32 = u64; + *u32 = (uint32_t)u64; return DECODE_OK; } @@ -525,7 +525,7 @@ UPB_NOINLINE int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d, UPB_ASSERT(ok < 0); return DECODE_OK; } else if (read < bytes && memcmp(&data, &expected, read) == 0) { - return suspend_save(d); + return (int32_t)suspend_save(d); } else { return DECODE_MISMATCH; } @@ -545,7 +545,7 @@ int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum, have_tag: if (fieldnum == 0) { seterr(d, "Saw invalid field number (0)"); - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } switch (wire_type) { @@ -567,7 +567,9 @@ have_tag: break; } case UPB_WIRE_TYPE_START_GROUP: - CHECK_SUSPEND(pushtagdelim(d, -fieldnum)); + if (!pushtagdelim(d, -fieldnum)) { + return (int32_t)upb_pbdecoder_suspend(d); + } break; case UPB_WIRE_TYPE_END_GROUP: if (fieldnum == -d->top->groupnum) { @@ -576,12 +578,12 @@ have_tag: return DECODE_ENDGROUP; } else { seterr(d, "Unmatched ENDGROUP tag."); - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } break; default: seterr(d, "Invalid wire type"); - return upb_pbdecoder_suspend(d); + return (int32_t)upb_pbdecoder_suspend(d); } if (d->top->groupnum >= 0) { @@ -753,7 +755,7 @@ size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group, CHECK_SUSPEND(upb_sink_endsubmsg(d->top->sink, subsink, arg)); ) VMCASE(OP_STARTSTR, - uint32_t len = delim_remaining(d); + uint32_t len = (uint32_t)delim_remaining(d); upb_pbdecoder_frame *outer = outer_frame(d); CHECK_SUSPEND(upb_sink_startstr(outer->sink, arg, len, &d->top->sink)); if (len == 0) { @@ -761,7 +763,7 @@ size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group, } ) VMCASE(OP_STRING, - uint32_t len = curbufleft(d); + uint32_t len = (uint32_t)curbufleft(d); size_t n = upb_sink_putstring(d->top->sink, arg, d->ptr, len, handle); if (n > len) { if (n > delim_remaining(d)) { diff --git a/upb/pb/encoder.c b/upb/pb/encoder.c index d108a643d3..257e1474ca 100644 --- a/upb/pb/encoder.c +++ b/upb/pb/encoder.c @@ -248,7 +248,7 @@ static bool start_delim(upb_pb_encoder *e) { e->runbegin = e->ptr; } - *e->top = e->segptr - e->segbuf; + *e->top = (int)(e->segptr - e->segbuf); e->segptr->seglen = 0; e->segptr->msglen = 0; diff --git a/upb/pb/varint.int.h b/upb/pb/varint.int.h index 293067a5cb..59158d3b75 100644 --- a/upb/pb/varint.int.h +++ b/upb/pb/varint.int.h @@ -40,7 +40,8 @@ UPB_INLINE uint64_t byteswap64(uint64_t val) { /* Zig-zag encoding/decoding **************************************************/ -UPB_INLINE int32_t upb_zzdec_32(uint32_t n) { +UPB_INLINE int32_t upb_zzdec_32(uint64_t _n) { + uint32_t n = (uint32_t)_n; return (n >> 1) ^ -(int32_t)(n & 1); } UPB_INLINE int64_t upb_zzdec_64(uint64_t n) { diff --git a/upb/reflection.c b/upb/reflection.c index 695cae0513..d032eccee4 100644 --- a/upb/reflection.c +++ b/upb/reflection.c @@ -189,10 +189,10 @@ void upb_msg_set(upb_msg *msg, const upb_fielddef *f, upb_msgval val, bool upb_msg_next(const upb_msg *msg, const upb_msgdef *m, const upb_symtab *ext_pool, const upb_fielddef **out_f, upb_msgval *out_val, size_t *iter) { - int i = *iter; + size_t i = *iter; const upb_msgval zero = {0}; const upb_fielddef *f; - while ((f = _upb_msgdef_field(m, ++i)) != NULL) { + while ((f = _upb_msgdef_field(m, (int)++i)) != NULL) { upb_msgval val = _upb_msg_getraw(msg, f); /* Skip field if unset or empty. */