diff options
author | Randall Spangler <rspangler@chromium.org> | 2014-12-01 15:06:53 -0800 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-12-03 21:29:22 +0000 |
commit | 45562fb05a63e5f5a373d38e068a7e1100c92e7e (patch) | |
tree | 2d7caaf8fc9ee33c2bd91e51669d358fcb316ad2 /tests | |
parent | 42a850059ca07f5e14fdf31990a35ad63e3f1bd8 (diff) | |
download | vboot_reference-45562fb05a63e5f5a373d38e068a7e1100c92e7e.tar.gz |
vboot2: Use calloc() in host lib and unit tests
This is cleaner than malloc() immediately followed by memset().
BUG=chromium:423882
BRANCH=none
TEST=VBOOT2=1 make runtests
Change-Id: Iac32ca54ba18ef6722c6e9c58d521d5337a816b2
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/232770
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/vb2_common_tests.c | 3 | ||||
-rw-r--r-- | tests/vb2_host_key_tests.c | 3 | ||||
-rw-r--r-- | tests/vb2_host_sig_tests.c | 6 |
3 files changed, 4 insertions, 8 deletions
diff --git a/tests/vb2_common_tests.c b/tests/vb2_common_tests.c index 199b1e05..89c8307d 100644 --- a/tests/vb2_common_tests.c +++ b/tests/vb2_common_tests.c @@ -665,8 +665,7 @@ static void test_verify_fw_preamble(void) /* Now that the total size is known, create the real preamble */ buf_size = fp.c.total_size; - buf = malloc(buf_size); - memset(buf, 0, buf_size); + buf = calloc(1, buf_size); memcpy(buf, &fp, sizeof(fp)); memcpy(buf + fp.c.fixed_size, desc, sizeof(desc)); diff --git a/tests/vb2_host_key_tests.c b/tests/vb2_host_key_tests.c index 5780691a..451366f7 100644 --- a/tests/vb2_host_key_tests.c +++ b/tests/vb2_host_key_tests.c @@ -187,8 +187,7 @@ static void public_key_tests(const struct alg_combo *combo, vb2_public_key_free(key); bufsize = vb2_packed_key_size(combo->sig_alg); - buf = malloc(bufsize); - memset(buf, 0, bufsize); + buf = calloc(1, bufsize); vb2_write_file(testfile, buf, bufsize - 1); TEST_EQ(vb2_public_key_read_keyb(&key, testfile), diff --git a/tests/vb2_host_sig_tests.c b/tests/vb2_host_sig_tests.c index 76e128c9..809c7b04 100644 --- a/tests/vb2_host_sig_tests.c +++ b/tests/vb2_host_sig_tests.c @@ -117,8 +117,7 @@ static void sig_tests(const struct alg_combo *combo, c_sig_offs = sizeof(*c) + 24; TEST_SUCC(vb2_sig_size_for_key(&size, prik, NULL), "Sig size"); bufsize = c_sig_offs + size; - buf = malloc(bufsize); - memset(buf, 0, bufsize); + buf = calloc(1, bufsize); memset(buf + sizeof(*c), 0x12, 24); c = (struct vb2_struct_common *)buf; c->total_size = bufsize; @@ -135,8 +134,7 @@ static void sig_tests(const struct alg_combo *combo, /* Multiply sign an object */ TEST_SUCC(vb2_sig_size_for_keys(&size, priks, 2), "Sigs size"); bufsize = c_sig_offs + size; - buf = malloc(bufsize); - memset(buf, 0, bufsize); + buf = calloc(1, bufsize); memset(buf + sizeof(*c), 0x12, 24); c = (struct vb2_struct_common *)buf; c->total_size = bufsize; |