From b63e2a87a75dce8941d087c8736c5a35544ab3b0 Mon Sep 17 00:00:00 2001 From: Evan Green Date: Thu, 1 Aug 2019 11:20:14 -0700 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1730605 --- include/printf.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'include/printf.h') diff --git a/include/printf.h b/include/printf.h index c55c8f7d2b..6e245a3f2a 100644 --- a/include/printf.h +++ b/include/printf.h @@ -40,10 +40,6 @@ * Type may be: * - 'c' - character * - 's' - null-terminated ASCII string - * - 'h' - binary data, print as hex; precision is length of data in bytes. - * So "%.8h" prints 8 bytes of binary data - * - 'pP'- raw pointer. %p followed by another character represents a %p - * extension. * - 'd' - signed integer * - 'i' - signed integer if CONFIG_PRINTF_LEGACY_LI_FORMAT is set (ignore l) * - 'u' - unsigned integer @@ -52,6 +48,9 @@ * - 'b' - unsigned integer, print as binary * * Special format codes: + * - '%ph' - binary data, print as hex; Use HEX_BUF(buffer, size) to encode + * parameters. + * - '%pP' - raw pointer. * - "%pT" - current time in seconds - interpreted as "%.6T" for precision. * Supply PRINTF_TIMESTAMP_NOW to use the current time, or supply a * pointer to a 64-bit timestamp to print. -- cgit v1.2.1