Message ID | 20230612080959.571293-8-wxjstz@126.com |
---|---|
State | Superseded |
Headers | show |
Series | Improve sbi_console | expand |
On Mon, Jun 12, 2023 at 1:40 PM Xiang W <wxjstz@126.com> wrote: > > Fix two bug: > > printf("%#08x", 0x123); /* print 0000x123 */ > > printf("%#x", 0); /* print 0x0 */ > > Signed-off-by: Xiang W <wxjstz@126.com> Looks good to me. Reviewed-by: Anup Patel <anup@brainfault.org> Regards, Anup > --- > lib/sbi/sbi_console.c | 36 +++++++++++++++++++++++------------- > 1 file changed, 23 insertions(+), 13 deletions(-) > > diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c > index 047c51e..6f714f0 100644 > --- a/lib/sbi/sbi_console.c > +++ b/lib/sbi/sbi_console.c > @@ -227,23 +227,33 @@ static int printi(char **out, u32 *out_len, long long i, > } > } > > - if (flags & PAD_ALTERNATE) { > - if ((b == 16) && (letbase == 'A')) { > - *--s = 'X'; > - } else if ((b == 16) && (letbase == 'a')) { > - *--s = 'x'; > - } > - *--s = '0'; > - } > - > - if (sign) { > - if (width && (flags & PAD_ZERO)) { > + if (flags & PAD_ZERO) { > + if (sign) { > printc(out, out_len, sign); > ++pc; > --width; > - } else { > - *--s = sign; > } > + if (i && (flags & PAD_ALTERNATE)) { > + if (b == 16 || b == 8) { > + printc(out, out_len, '0'); > + ++pc; > + --width; > + } > + if (b == 16) { > + printc(out, out_len, 'x' - 'a' + letbase); > + ++pc; > + --width; > + } > + } > + } else { > + if (i && (flags & PAD_ALTERNATE)) { > + if (b == 16) > + *--s = 'x' - 'a' + letbase; > + if (b == 16 || b == 8) > + *--s = '0'; > + } > + if (sign) > + *--s = sign; > } > > return pc + prints(out, out_len, s, width, flags); > -- > 2.39.2 >
diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 047c51e..6f714f0 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -227,23 +227,33 @@ static int printi(char **out, u32 *out_len, long long i, } } - if (flags & PAD_ALTERNATE) { - if ((b == 16) && (letbase == 'A')) { - *--s = 'X'; - } else if ((b == 16) && (letbase == 'a')) { - *--s = 'x'; - } - *--s = '0'; - } - - if (sign) { - if (width && (flags & PAD_ZERO)) { + if (flags & PAD_ZERO) { + if (sign) { printc(out, out_len, sign); ++pc; --width; - } else { - *--s = sign; } + if (i && (flags & PAD_ALTERNATE)) { + if (b == 16 || b == 8) { + printc(out, out_len, '0'); + ++pc; + --width; + } + if (b == 16) { + printc(out, out_len, 'x' - 'a' + letbase); + ++pc; + --width; + } + } + } else { + if (i && (flags & PAD_ALTERNATE)) { + if (b == 16) + *--s = 'x' - 'a' + letbase; + if (b == 16 || b == 8) + *--s = '0'; + } + if (sign) + *--s = sign; } return pc + prints(out, out_len, s, width, flags);