From 2a233df808e7f76d66b499463feb9333d27377f7 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 16 Apr 2024 20:48:47 -0700 Subject: [PATCH] Avoid returning a pointer to internal storage of `upb_MiniTable.subs`. PiperOrigin-RevId: 625544972 --- upb/mini_table/internal/message.h | 6 +++--- upb/wire/internal/decode_fast.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/upb/mini_table/internal/message.h b/upb/mini_table/internal/message.h index e044c0e48cf82..5b49e0ff6511f 100644 --- a/upb/mini_table/internal/message.h +++ b/upb/mini_table/internal/message.h @@ -62,7 +62,7 @@ struct upb_MiniTable { const char* UPB_PRIVATE(full_name); #endif -#ifdef UPB_FASTTABLE_ENABLED +#if UPB_FASTTABLE // To statically initialize the tables of variable length, we need a flexible // array member, and we need to compile in gnu99 mode (constant initialization // of flexible array members is a GNU extension, not in C99 unfortunately. @@ -97,9 +97,9 @@ UPB_API_INLINE const struct upb_MiniTableField* upb_MiniTable_GetFieldByIndex( return &m->UPB_ONLYBITS(fields)[i]; } -UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE( +UPB_INLINE const union upb_MiniTableSub UPB_PRIVATE( _upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) { - return &m->UPB_PRIVATE(subs)[i]; + return m->UPB_PRIVATE(subs)[i]; } UPB_API_INLINE const struct upb_MiniTable* upb_MiniTable_GetSubMessageTable( diff --git a/upb/wire/internal/decode_fast.c b/upb/wire/internal/decode_fast.c index 67be4135c4eba..843b46e3fa04b 100644 --- a/upb/wire/internal/decode_fast.c +++ b/upb/wire/internal/decode_fast.c @@ -912,7 +912,7 @@ const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, const char* ptr, uint32_t submsg_idx = (data >> 16) & 0xff; \ const upb_MiniTable* tablep = decode_totablep(table); \ const upb_MiniTable* subtablep = upb_MiniTableSub_Message( \ - *UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)(tablep, submsg_idx)); \ + UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)(tablep, submsg_idx)); \ fastdecode_submsgdata submsg = {decode_totable(subtablep)}; \ fastdecode_arr farr; \ \