[PATCH v2] lib: sbi: Fix printf handling of long long

Andrew Jones ajones at ventanamicro.com
Wed Jul 27 08:50:09 PDT 2022


On Wed, Jul 27, 2022 at 11:06:12PM +0800, dramforever wrote:
> 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
>

We need to remove all acnt lines from print() and the variable itself as
it's unused after the while loop above is removed.

Thanks,
drew 



More information about the opensbi mailing list