summaryrefslogtreecommitdiff
path: root/common/vboot_hash.c
diff options
context:
space:
mode:
authorEvan Green <evgreen@chromium.org>2019-08-01 11:20:14 -0700
committerCommit Bot <commit-bot@chromium.org>2019-10-05 00:47:41 +0000
commitb63e2a87a75dce8941d087c8736c5a35544ab3b0 (patch)
tree32a4bfe24554a38c6ad30dcb38911796d2acea50 /common/vboot_hash.c
parent60d66714d3b41d69942652650672fd5259815538 (diff)
downloadchrome-ec-b63e2a87a75dce8941d087c8736c5a35544ab3b0.tar.gz
printf: Convert %h to %ph
In order to make printf more standard, use %ph. Pass a pointer to a struct describing the buffer, including its size. Add a convenience macro so that conversion between the old style and new style is purely mechanical. The old style of %h cannot be converted directly to %ph as-is because the C standard doesn't allow flags, precision, or field width on %p. Ultimately the goal is to enable compile-time printf format checking. This gets us one step closer to that. BUG=chromium:984041 TEST=make -j buildall BRANCH=None Cq-Depend:chrome-internal:1559798,chrome-internal:1560598 Change-Id: I9c0ca124a048314c9b62d64bd55b36be55034e0e Signed-off-by: Evan Green <evgreen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1730605
Diffstat (limited to 'common/vboot_hash.c')
-rw-r--r--common/vboot_hash.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/common/vboot_hash.c b/common/vboot_hash.c
index 4d12af7c7b..0642e09e3c 100644
--- a/common/vboot_hash.c
+++ b/common/vboot_hash.c
@@ -141,7 +141,7 @@ static void vboot_hash_next_chunk(void)
if (curr_pos >= data_size) {
/* Store the final hash */
hash = SHA256_final(&ctx);
- CPRINTS("hash done %.*h", SHA256_PRINT_SIZE, hash);
+ CPRINTS("hash done %ph", HEX_BUF(hash, SHA256_PRINT_SIZE));
in_progress = 0;
@@ -331,7 +331,7 @@ static int command_hash(int argc, char **argv)
else if (in_progress)
ccprintf("(in progress)\n");
else if (hash)
- ccprintf("%.*h\n", SHA256_DIGEST_SIZE, hash);
+ ccprintf("%ph\n", HEX_BUF(hash, SHA256_DIGEST_SIZE));
else
ccprintf("(invalid)\n");