Edward O'Callaghan has uploaded this change for review.
tests/: Assert on NULL heap allocations in tests
Change-Id: Id2adcfe859fb25d2a7f0734655c6b9a58c0890b6
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
---
M tests/chip.c
M tests/chip_wp.c
M tests/helpers.c
M tests/raiden_debug_spi.c
4 files changed, 23 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/19/71919/1
diff --git a/tests/chip.c b/tests/chip.c
index 194e114..5b025d3 100644
--- a/tests/chip.c
+++ b/tests/chip.c
@@ -279,6 +279,7 @@
const char *const filename = "read_chip.test";
unsigned long size = mock_chip.total_size * 1024;
unsigned char *buf = calloc(size, sizeof(unsigned char));
+ assert_non_null(buf);
printf("Read chip operation started.\n");
assert_int_equal(0, flashrom_image_read(&flashctx, buf, size));
@@ -316,6 +317,7 @@
const char *const filename = "read_chip.test";
unsigned long size = mock_chip.total_size * 1024;
unsigned char *buf = calloc(size, sizeof(unsigned char));
+ assert_non_null(buf);
printf("Read chip operation started.\n");
assert_int_equal(0, flashrom_image_read(&flashctx, buf, size));
@@ -365,6 +367,7 @@
const char *const filename = "-";
unsigned long size = mock_chip.total_size * 1024;
uint8_t *const newcontents = malloc(size);
+ assert_non_null(newcontents);
printf("Write chip operation started.\n");
assert_int_equal(0, read_buf_from_file(newcontents, size, filename));
@@ -403,6 +406,7 @@
const char *const filename = "-";
unsigned long size = mock_chip.total_size * 1024;
uint8_t *const newcontents = malloc(size);
+ assert_non_null(newcontents);
printf("Write chip operation started.\n");
assert_int_equal(0, read_buf_from_file(newcontents, size, filename));
@@ -452,6 +456,7 @@
const char *const filename = "-";
unsigned long size = mock_chip.total_size * 1024;
uint8_t *const newcontents = malloc(size);
+ assert_non_null(newcontents);
printf("Verify chip operation started.\n");
assert_int_equal(0, read_buf_from_file(newcontents, size, filename));
@@ -491,6 +496,7 @@
const char *const filename = "-";
unsigned long size = mock_chip.total_size * 1024;
uint8_t *const newcontents = malloc(size);
+ assert_non_null(newcontents);
/*
* Dummyflasher controls chip state and fully emulates reads and writes,
diff --git a/tests/chip_wp.c b/tests/chip_wp.c
index f20b500..cb9b3ab 100644
--- a/tests/chip_wp.c
+++ b/tests/chip_wp.c
@@ -269,6 +269,7 @@
* be optimized away. */
unsigned long size = flashrom_flash_getsize(&flash);
uint8_t *const contents = malloc(size);
+ assert_non_null(contents);
memset(contents, UNERASED_VALUE(&flash), size);
assert_int_equal(0, flashrom_image_write(&flash, contents, size, NULL));
free(contents);
diff --git a/tests/helpers.c b/tests/helpers.c
index e2e652e..271fb48 100644
--- a/tests/helpers.c
+++ b/tests/helpers.c
@@ -45,6 +45,7 @@
const char src0[] = "hello";
const char src1[] = " world";
char *dest = calloc(1, 1);
+ assert_non_null(dest);
dest = strcat_realloc(dest, src0);
dest = strcat_realloc(dest, src1);
assert_string_equal("hello world", dest);
diff --git a/tests/raiden_debug_spi.c b/tests/raiden_debug_spi.c
index f5bf185..5c79a90 100644
--- a/tests/raiden_debug_spi.c
+++ b/tests/raiden_debug_spi.c
@@ -19,6 +19,7 @@
static ssize_t raiden_debug_libusb_get_device_list(void *state, libusb_context *ctx, libusb_device ***list)
{
*list = calloc(1, sizeof(**list));
+ assert_non_null(*list);
/*
* libusb_device is opaque type, it is tossed around between libusb functions but always
@@ -48,10 +49,14 @@
void *state, libusb_device *dev, uint8_t config_index, struct libusb_config_descriptor **config)
{
*config = calloc(1, sizeof(**config));
+ assert_non_null(*config);
struct libusb_endpoint_descriptor *tmp_endpoint = calloc(2, sizeof(*tmp_endpoint));
+ assert_non_null(tmp_endpoint);
struct libusb_interface_descriptor *tmp_interface_desc = calloc(1, sizeof(*tmp_interface_desc));
+ assert_non_null(tmp_interface_desc);
struct libusb_interface *tmp_interface = calloc(1, sizeof(*tmp_interface));
+ assert_non_null(tmp_interface);
/* in endpoint */
tmp_endpoint[0].bEndpointAddress = 0x80;
To view, visit change 71919. To unsubscribe, or for help writing mail filters, visit settings.