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 <jacz@semihalf.com>
Change-Id: I27678a4eb01a0e6bedd0ba8c4b22a1b01afeaf12
Reviewed-on: https://review.coreboot.org/c/coreboot/+/52263
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
diff --git a/tests/lib/bootmem-test.c b/tests/lib/bootmem-test.c
index 85a0136..b571ccb 100644
--- a/tests/lib/bootmem-test.c
+++ b/tests/lib/bootmem-test.c
@@ -162,13 +162,15 @@
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 @@
/* 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);
}