Initialize mini table subs, so that upb_MiniTable_Build creates stable unlinked table.

PiperOrigin-RevId: 479630135
pull/13171/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 65946dc0e7
commit 3faf958b3d
  1. 4
      upb/mini_table.c
  2. 16
      upb/mini_table_test.cc

@ -768,7 +768,9 @@ static const char* upb_MtDecoder_ParseModifier(upb_MtDecoder* d,
static void upb_MtDecoder_AllocateSubs(upb_MtDecoder* d, uint32_t sub_count) {
size_t subs_bytes = sizeof(*d->table->subs) * sub_count;
d->table->subs = upb_Arena_Malloc(d->arena, subs_bytes);
void* subs = upb_Arena_Malloc(d->arena, subs_bytes);
memset(subs, 0, subs_bytes);
d->table->subs = subs;
upb_MtDecoder_CheckOutOfMemory(d, d->table->subs);
}

@ -236,6 +236,22 @@ TEST(MiniTableEnumTest, Enum) {
}
}
TEST_P(MiniTableTest, SubsInitializedToNull) {
upb::Arena arena;
upb::MtDataEncoder e;
// Create mini table with 2 message fields.
ASSERT_TRUE(e.StartMessage(0));
ASSERT_TRUE(e.PutField(kUpb_FieldType_Message, 15, 0));
ASSERT_TRUE(e.PutField(kUpb_FieldType_Message, 16, 0));
upb::Status status;
upb_MiniTable* table = upb_MiniTable_Build(
e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr());
ASSERT_NE(nullptr, table);
EXPECT_EQ(table->field_count, 2);
EXPECT_EQ(table->subs[0].submsg, nullptr);
EXPECT_EQ(table->subs[1].submsg, nullptr);
}
TEST(MiniTableEnumTest, PositiveAndNegative) {
upb::Arena arena;
upb::MtDataEncoder e;

Loading…
Cancel
Save