diff options
author | Evan Green <evgreen@chromium.org> | 2019-08-01 11:20:14 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-10-05 00:47:41 +0000 |
commit | b63e2a87a75dce8941d087c8736c5a35544ab3b0 (patch) | |
tree | 32a4bfe24554a38c6ad30dcb38911796d2acea50 /common/host_command.c | |
parent | 60d66714d3b41d69942652650672fd5259815538 (diff) | |
download | chrome-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/host_command.c')
-rw-r--r-- | common/host_command.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/common/host_command.c b/common/host_command.c index be178f7b6c..eff1fac56b 100644 --- a/common/host_command.c +++ b/common/host_command.c @@ -666,8 +666,9 @@ static void host_command_debug_request(struct host_cmd_handler_args *args) } if (hcdebug >= HCDEBUG_PARAMS && args->params_size) - CPRINTS("HC 0x%02x.%d:%.*h", args->command, - args->version, args->params_size, args->params); + CPRINTS("HC 0x%02x.%d:%ph", args->command, + args->version, + HEX_BUF(args->params, args->params_size)); else CPRINTS("HC 0x%02x", args->command); } @@ -711,8 +712,8 @@ uint16_t host_command_process(struct host_cmd_handler_args *args) CPRINTS("HC 0x%02x err %d", args->command, rv); if (hcdebug >= HCDEBUG_PARAMS && args->response_size) - CPRINTS("HC resp:%.*h", args->response_size, - args->response); + CPRINTS("HC resp:%ph", + HEX_BUF(args->response, args->response_size)); return rv; } @@ -892,7 +893,8 @@ static int command_host_command(int argc, char **argv) if (res != EC_RES_SUCCESS) ccprintf("Command returned %d\n", res); else if (args.response_size) - ccprintf("Response: %.*h\n", args.response_size, cmd_params); + ccprintf("Response: %ph\n", + HEX_BUF(cmd_params, args.response_size)); else ccprintf("Command succeeded; no response.\n"); |