Explorar o código

%d now represents signed decimal, %u represents unsigned decimal.

This patch changes the behavior of Print() slightly. %d is now signed decimal,
and %u (new) is unsigned decimal. Previously, although ValueToString supports
signed decimal printing, %d always read args as UINTxx.

Old behavior:
Print(L"%d\n", -4) -> "4294967292"

New behavior:
Print(L"%d\n, -4) -> "-4"
Print(L"%u\n", -4) -> "4294967292"

If you want to keep complete backwards compatibility you could leave %d alone
and make something else (probably shouldn't be %u to avoid confusion) be
signed decimal. But this way it agrees with the usual use of %d and %u.

Signed-off-by: Nathan Blythe <[email protected]>
Signed-off-by: Nigel Croxon <[email protected]>
Nigel Croxon %!s(int64=9) %!d(string=hai) anos
pai
achega
1acb1d9dae
Modificáronse 1 ficheiros con 14 adicións e 4 borrados
  1. 14 4
      lib/print.c

+ 14 - 4
lib/print.c

@@ -998,7 +998,8 @@ Routine Description:
     s       -   unicode string
     X       -   fixed 8 byte value in hex
     x       -   hex value
-    d       -   value as decimal    
+    d       -   value as signed decimal
+    u       -   value as unsigned decimal
     c       -   Unicode char
     t       -   EFI time structure
     g       -   Pointer to GUID
@@ -1144,15 +1145,24 @@ Returns:
                 GuidToString (Item.Item.pw, va_arg(ps->args, EFI_GUID *));
                 break;
 
-            case 'd':
+            case 'u':
                 Item.Item.pw = Item.Scratch;
                 ValueToString (
                     Item.Item.pw, 
                     Item.Comma, 
                     Item.Long ? va_arg(ps->args, UINT64) : va_arg(ps->args, UINT32)
                     );
-                break
-                    ;
+                break;
+
+            case 'd':
+                Item.Item.pw = Item.Scratch;
+                ValueToString (
+                    Item.Item.pw, 
+                    Item.Comma, 
+                    Item.Long ? va_arg(ps->args, INT64) : va_arg(ps->args, INT32)
+                    );
+                break;
+
             case 't':
                 Item.Item.pw = Item.Scratch;
                 TimeToString (Item.Item.pw, va_arg(ps->args, EFI_TIME *));