From 0c2d7b648e1ea433aad8123538632d4edff6eb85 Mon Sep 17 00:00:00 2001 From: Evan Green Date: Mon, 23 Sep 2019 13:07:06 -0700 Subject: printf: Convert %l to %ll In order to make our printf more standard, utilize %ll for long long arguments, rather than %l. This does cost a little bit in flash space for that extra l in a couple of places, but enables us to turn on compile-time printf format checking. For this commit only, the semantics are such that both %l and %ll take 64-bit arguments. In the next commit, %l goes to its correct behavior of taking a sizeof(long) argument. BUG=chromium:984041 TEST=make -j buildall BRANCH=none Cq-Depend:chrome-internal:1863686,chrome-internal:1860161,chrome-internal:1914029 Change-Id: I18081b55a8dbf5ef8ec15fc499ca75e59d31da58 Signed-off-by: Evan Green Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1819652 Reviewed-by: Jack Rosenthal --- common/printf.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'common/printf.c') diff --git a/common/printf.c b/common/printf.c index 3c7bc5feca..68f66815b9 100644 --- a/common/printf.c +++ b/common/printf.c @@ -226,10 +226,30 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context, /* * Handle length: * %l - long + * %ll - long long * %z - size_t */ if (c == 'l') { + + /* + * For just this commit, allow both %l and %ll + * to be 64-bit. This is obviously wrong, but + * enables this change to be cherry-picked + * into firmware branches without changing + * semantics for any existing printf calls. + * This is removed in the subsequent commit on + * master. + */ flags |= PF_64BIT; + if (sizeof(long) == sizeof(uint64_t)) + flags |= PF_64BIT; + + c = *format++; + if (c == 'l') { + flags |= PF_64BIT; + c = *format++; + } + } else if (c == 'z') { if (sizeof(size_t) == sizeof(uint64_t)) flags |= PF_64BIT; -- cgit v1.2.1