Address review comments and fix compile warnings.

pull/13171/head
Joshua Haberman 7 years ago
parent 806ffc1d20
commit 6b87674221
  1. 2
      tests/conformance_upb.c
  2. 2
      upb/decode.c
  3. 10
      upb/encode.c

@ -33,7 +33,7 @@ bool CheckedRead(int fd, void *buf, size_t len) {
}
void CheckedWrite(int fd, const void *buf, size_t len) {
if (write(fd, buf, len) != len) {
if ((size_t)write(fd, buf, len) != len) {
perror("writing to test runner");
exit(1);
}

@ -385,7 +385,7 @@ static bool upb_decode_fixedpacked(upb_array *arr, upb_stringview data,
int elements = data.size / elem_size;
void *field_mem;
CHK(elements * elem_size == data.size);
CHK((size_t)(elements * elem_size) == data.size);
field_mem = upb_array_add(arr, elements);
CHK(field_mem);
memcpy(field_mem, data.data, data.size);

@ -256,9 +256,11 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem,
const upb_msglayout_msginit_v1 *m,
const upb_msglayout_fieldinit_v1 *f,
bool is_proto3) {
bool skip_zero_value = is_proto3 && f->oneof_index == UPB_NOT_IN_ONEOF;
#define CASE(ctype, type, wire_type, encodeval) do { \
ctype val = *(ctype*)field_mem; \
if (is_proto3 && f->oneof_index == UPB_NOT_IN_ONEOF && val == 0) { \
if (skip_zero_value && val == 0) { \
return true; \
} \
return upb_put_ ## type(e, encodeval) && \
@ -292,7 +294,7 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem,
case UPB_DESCRIPTOR_TYPE_STRING:
case UPB_DESCRIPTOR_TYPE_BYTES: {
upb_stringview view = *(upb_stringview*)field_mem;
if (is_proto3 && f->oneof_index == UPB_NOT_IN_ONEOF && view.size == 0) {
if (skip_zero_value && view.size == 0) {
return true;
}
return upb_put_bytes(e, view.data, view.size) &&
@ -303,7 +305,7 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem,
size_t size;
void *submsg = *(void**)field_mem;
const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index];
if (is_proto3 && f->oneof_index == UPB_NOT_IN_ONEOF && submsg == NULL) {
if (skip_zero_value && submsg == NULL) {
return true;
}
return upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) &&
@ -314,7 +316,7 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem,
size_t size;
void *submsg = *(void**)field_mem;
const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index];
if (is_proto3 && f->oneof_index == UPB_NOT_IN_ONEOF && submsg == NULL) {
if (skip_zero_value && submsg == NULL) {
return true;
}
return upb_encode_message(e, submsg, subm, &size) &&

Loading…
Cancel
Save