diff options
| -rw-r--r-- | kernel/vsprintf.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/kernel/vsprintf.c b/kernel/vsprintf.c index 4fdb2c4..a566b83 100644 --- a/kernel/vsprintf.c +++ b/kernel/vsprintf.c @@ -1,4 +1,5 @@ #include <stdarg.h> +#include <stdbool.h> #include <stdint.h> enum TYPE { @@ -16,6 +17,7 @@ enum FLAGS { }; static void hex(char **str, char flags, int fwidth, int size, int x) { + bool seen; int i, y, len; char c; char *prefl = "0x"; @@ -35,9 +37,12 @@ static void hex(char **str, char flags, int fwidth, int size, int x) { /* calculate the number of digits */ len = 0; y = x; + seen = false; for(i = 0; i < sizeof(y) << 1; i++) { c = ((unsigned int) y >> 28); if(c) + seen = true; + if(c || seen) len++; y = y << 4; } @@ -50,6 +55,7 @@ static void hex(char **str, char flags, int fwidth, int size, int x) { *(*str)++ = c; /* actually print the digits */ + seen = false; for(i = 0; i < sizeof(x) << 1; i++) { c = ((unsigned int) x >> 28) + '0'; if(c > '9') { @@ -59,6 +65,8 @@ static void hex(char **str, char flags, int fwidth, int size, int x) { } if(c != '0') + seen = true; + if(c != '0' || seen) *(*str)++ = c; x = x << 4; |
