From ec8eef0a6b4d29d5a9bf60476b77ffd05eb32860 Mon Sep 17 00:00:00 2001 From: Jakub Czapiga Date: Mon, 12 Apr 2021 11:25:44 +0200 Subject: tests/lib/bootmem-test: Add initialization of lb_mem fields Add missing initialization of tag and size fields. Include initial size value in assertion in test_bootmem_write_mem_table(). Found-by: Coverity CID 1452250 Signed-off-by: Jakub Czapiga Change-Id: I27678a4eb01a0e6bedd0ba8c4b22a1b01afeaf12 Reviewed-on: https://review.coreboot.org/c/coreboot/+/52263 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner Reviewed-by: Paul Fagerburg --- tests/lib/bootmem-test.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/lib/bootmem-test.c b/tests/lib/bootmem-test.c index 85a01364e5a2..b571ccbb514c 100644 --- a/tests/lib/bootmem-test.c +++ b/tests/lib/bootmem-test.c @@ -162,13 +162,15 @@ static void test_bootmem_write_mem_table(void **state) memset(sentinel_value_buffer, 0x77, required_unused_space_size); lb_mem = malloc(lb_mem_max_size); + lb_mem->tag = LB_TAG_MEMORY; + lb_mem->size = sizeof(*lb_mem); /* Fill rest of buffer with sentinel value */ memset(((u8 *)lb_mem) + expected_allocation_size, 0x77, required_unused_space_size); bootmem_write_memory_table(lb_mem); /* There should be only `os_ranges_mock` entries visible in coreboot table */ - assert_int_equal(lb_mem->size, + assert_int_equal(lb_mem->size, sizeof(*lb_mem) + ARRAY_SIZE(os_ranges_mock) * sizeof(struct lb_memory_range)); assert_memory_equal(sentinel_value_buffer, ((u8 *)lb_mem) + expected_allocation_size, @@ -230,9 +232,12 @@ static void init_memory_table_library(void) /* Allocate space for 10 lb_mem entries to be safe */ lb_mem = malloc(sizeof(*lb_mem) + 10 * sizeof(struct lb_memory_range)); + lb_mem->tag = LB_TAG_MEMORY; + lb_mem->size = sizeof(*lb_mem); /* We need to call this only to initialize library */ bootmem_write_memory_table(lb_mem); + free(lb_mem); } -- cgit v1.2.3