Fixed UBSAN errors.

pull/13171/head
Joshua Haberman 3 years ago
parent 8ede0d552d
commit 05d23ea955
  1. 2
      upb/encode.c
  2. 10
      upb/mini_table.c

@ -449,7 +449,7 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg,
return ch != 0; return ch != 0;
} }
#if UINTPTR_MAX == 0xffffffff #if UINTPTR_MAX == 0xffffffff
case upb_FieldRep_Pointer: case kUpb_FieldRep_Pointer:
#endif #endif
case kUpb_FieldRep_4Byte: { case kUpb_FieldRep_4Byte: {
uint32_t u32; uint32_t u32;

@ -561,7 +561,7 @@ static void upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr, size_t len,
uint32_t last_field_number = 0; uint32_t last_field_number = 0;
bool need_dense_below = d->table != NULL; bool need_dense_below = d->table != NULL;
d->end = ptr + len; d->end = UPB_PTRADD(ptr, len);
while (ptr < d->end) { while (ptr < d->end) {
char ch = *ptr++; char ch = *ptr++;
@ -650,8 +650,10 @@ static bool upb_MtDecoder_SortLayoutItems(upb_MtDecoder* d) {
upb_MtDecoder_PushItem(d, item); upb_MtDecoder_PushItem(d, item);
} }
qsort(d->vec.data, d->vec.size, sizeof(*d->vec.data), if (d->vec.size) {
upb_MtDecoder_CompareFields); qsort(d->vec.data, d->vec.size, sizeof(*d->vec.data),
upb_MtDecoder_CompareFields);
}
return true; return true;
} }
@ -735,7 +737,7 @@ size_t upb_MtDecoder_Place(upb_MtDecoder* d, upb_FieldRep rep) {
} }
static bool upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) { static bool upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) {
upb_LayoutItem* end = d->vec.data + d->vec.size; upb_LayoutItem* end = UPB_PTRADD(d->vec.data, d->vec.size);
// Compute offsets. // Compute offsets.
for (upb_LayoutItem* item = d->vec.data; item < end; item++) { for (upb_LayoutItem* item = d->vec.data; item < end; item++) {

Loading…
Cancel
Save