summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiang W <[email protected]>2023-07-10 00:02:27 +0800
committerAnup Patel <[email protected]>2023-07-12 10:01:43 +0530
commitc6ee5ae5a485335fa28a5f74811f900d8da9f87d (patch)
tree8601db9dcb5e9ed4e4c12b4d4d869da1ed5d414f
parentfe0828142fa34a95b6933dd94e68ed528d4c5778 (diff)
lib: sbi: Fix printi
Fix two bug: > printf("%#08x", 0x123); /* print 0000x123 */ > printf("%#x", 0); /* print 0x0 */ Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
-rw-r--r--lib/sbi/sbi_console.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c
index 10b27c62..9e9f273f 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);