[PATCH v2] lib: sbi: Fix printf handling of long long
dramforever
dramforever at live.com
Wed Jul 27 08:06:12 PDT 2022
Read long long arguments directly using va_arg. Remove original hack for
RV32 that read a long long arg as two long args.
This un-breaks the case on RV64 where e.g. the long long is followed by
an odd number of ints:
sbi_printf("%d %lld", (int) 1, (long long) 2LL);
Signed-off-by: dramforever <dramforever at live.com>
---
lib/sbi/sbi_console.c | 18 ++----------------
1 file changed, 2 insertions(+), 16 deletions(-)
diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c
index 34c843d..f18411b 100644
--- a/lib/sbi/sbi_console.c
+++ b/lib/sbi/sbi_console.c
@@ -261,22 +261,8 @@ static int print(char **out, u32 *out_len, const char *format, va_list args)
continue;
}
if (*format == 'l' && *(format + 1) == 'l') {
- while (acnt &
- (sizeof(unsigned long long) - 1)) {
- va_arg(args, int);
- acnt += sizeof(int);
- }
- if (sizeof(unsigned long long) ==
- sizeof(unsigned long)) {
- tmp = va_arg(args, unsigned long long);
- acnt += sizeof(unsigned long long);
- } else {
- ((unsigned long *)&tmp)[0] =
- va_arg(args, unsigned long);
- ((unsigned long *)&tmp)[1] =
- va_arg(args, unsigned long);
- acnt += 2 * sizeof(unsigned long);
- }
+ tmp = va_arg(args, unsigned long long);
+ acnt += sizeof(unsigned long long);
if (*(format + 2) == 'u') {
format += 2;
pc += printi(out, out_len, tmp, 10, 0,
--
2.37.0
More information about the opensbi
mailing list