]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
kern/misc: Support octal printf format code
authorGlenn Washburn <development@efficientek.com>
Wed, 28 Jun 2023 07:38:22 +0000 (02:38 -0500)
committerDaniel Kiper <daniel.kiper@oracle.com>
Mon, 3 Jul 2023 11:44:44 +0000 (13:44 +0200)
Also add parenthesis to nested ternary operator to improve clarity.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/kern/misc.c

index 977535282a339a77adff908737a25c4731c50b5a..739cc56691a14de9f230b936793e49ef944d68f5 100644 (file)
@@ -666,7 +666,7 @@ grub_divmod64 (grub_uint64_t n, grub_uint64_t d, grub_uint64_t *r)
 static inline char *
 grub_lltoa (char *str, int c, unsigned long long n)
 {
-  unsigned base = ((c == 'x') || (c == 'X')) ? 16 : 10;
+  unsigned base = ((c == 'x') || (c == 'X')) ? 16 : ((c == 'o') ? 8 : 10);
   char *p;
 
   if ((long long) n < 0 && c == 'd')
@@ -681,9 +681,15 @@ grub_lltoa (char *str, int c, unsigned long long n)
     do
       {
        unsigned d = (unsigned) (n & 0xf);
-       *p++ = (d > 9) ? d + ((c == 'x') ? 'a' : 'A') - 10 : d + '0';
+       *p++ = (d > 9) ? (d + ((c == 'x') ? 'a' : 'A') - 10) : d + '0';
       }
     while (n >>= 4);
+  else if (base == 8)
+    do
+      {
+       *p++ = ((unsigned) (n & 0x7)) + '0';
+      }
+    while (n >>= 3);
   else
     /* BASE == 10 */
     do
@@ -782,6 +788,7 @@ parse_printf_arg_fmt (const char *fmt0, struct printf_args *args,
        case 'X':
        case 'u':
        case 'd':
+       case 'o':
        case 'c':
        case 'C':
        case 's':
@@ -880,6 +887,7 @@ parse_printf_arg_fmt (const char *fmt0, struct printf_args *args,
        {
        case 'x':
        case 'X':
+       case 'o':
        case 'u':
          args->ptr[curn].type = UNSIGNED_INT + longfmt;
          break;
@@ -1089,6 +1097,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0,
        case 'X':
        case 'u':
        case 'd':
+       case 'o':
          write_number (str, &count, max_len, format1, rightfill, zerofill, c, curarg);
          break;