From 7576a3bfc1e6e0ca6b0a8dbb0a185ddb453983db Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 16 Nov 2021 15:01:35 -0800 Subject: [PATCH] Avoid NULL + 0 when adding a list of 0 extensions. --- upb/def.c | 6 ++++-- upb/msg.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/upb/def.c b/upb/def.c index 6087293fcb..9f8303ed2a 100644 --- a/upb/def.c +++ b/upb/def.c @@ -2943,8 +2943,10 @@ static void build_filedef( resolve_msgdef(ctx, (upb_msgdef*)&file->top_lvl_msgs[i]); } - CHK_OOM( - _upb_extreg_add(ctx->symtab->extreg, file->ext_layouts, file->ext_count)); + if (file->ext_count) { + CHK_OOM(_upb_extreg_add(ctx->symtab->extreg, file->ext_layouts, + file->ext_count)); + } } static void remove_filedef(upb_symtab *s, upb_filedef *file) { diff --git a/upb/msg.c b/upb/msg.c index e96fd86c71..94c4c186a1 100644 --- a/upb/msg.c +++ b/upb/msg.c @@ -376,7 +376,7 @@ upb_extreg *upb_extreg_new(upb_arena *arena) { bool _upb_extreg_add(upb_extreg *r, const upb_msglayout_ext **e, size_t count) { char buf[EXTREG_KEY_SIZE]; const upb_msglayout_ext **start = e; - const upb_msglayout_ext **end = e + count; + const upb_msglayout_ext **end = UPB_PTRADD(e, count); for (; e < end; e++) { const upb_msglayout_ext *ext = *e; extreg_key(buf, ext->extendee, ext->field.number);