]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BasePrintLib/PrintLibInternal.c
Remove some junk informatin.
[mirror_edk2.git] / MdePkg / Library / BasePrintLib / PrintLibInternal.c
index 89d18b09a2c5ffeadcbf622403ea06f8979ccfd9..8f417fbf11489f4c9c18955b75706e087616c0e5 100644 (file)
@@ -92,7 +92,7 @@ BasePrintLibValueToString (
   Converts the decimal number specified by Value to a Null-terminated  \r
   string specified by Buffer containing at most Width characters.\r
   If Width is 0 then a width of  MAXIMUM_VALUE_CHARACTERS is assumed.\r
-  The total number of characters placed in Buffer is returned.\r
+  The number of characters in Buffer is returned not including the Null-terminator.\r
   If the conversion contains more than Width characters, then only the first\r
   Width characters are returned, and the total number of characters \r
   required to perform the conversion is returned.\r
@@ -117,10 +117,10 @@ BasePrintLibValueToString (
   @param  Flags     The bitmask of flags that specify left justification, zero pad,\r
                     and commas.\r
   @param  Value     The 64-bit signed value to convert to a string.\r
-  @param  Width            The maximum number of characters to place in Buffer.\r
+  @param  Width      The maximum number of characters to place in Buffer.\r
   @param  Increment Character increment in Buffer.\r
   \r
-  @return Total number of characters required to perform the conversion.\r
+  @return The number of characters in Buffer not including the Null-terminator.\r
 \r
 **/\r
 UINTN\r
@@ -138,19 +138,27 @@ BasePrintLibConvertValueToString (
   UINTN  Digits;\r
   UINTN  Index;\r
 \r
+  ASSERT (Buffer != NULL);\r
+  ASSERT (Width < MAXIMUM_VALUE_CHARACTERS);\r
+  //\r
+  // Make sure Flags can only contain supported bits.\r
+  //\r
+  ASSERT ((Flags & ~(LEFT_JUSTIFY | COMMA_TYPE | PREFIX_ZERO)) == 0);\r
+\r
   OriginalBuffer = Buffer;\r
 \r
   if (Width == 0 || (Flags & COMMA_TYPE) != 0) {\r
     Flags &= (~PREFIX_ZERO);\r
   }\r
 \r
-  if (Width == 0 || Width > (MAXIMUM_VALUE_CHARACTERS - 1)) {\r
+  if (Width == 0) {\r
     Width = MAXIMUM_VALUE_CHARACTERS - 1;\r
   }\r
 \r
   if (Value < 0) {\r
     Value = -Value;\r
     Buffer = BasePrintLibFillBuffer (Buffer, 1, '-', Increment);\r
+    Width--;\r
   }\r
 \r
   Count = BasePrintLibValueToString (ValueBuffer, Value, 10);\r
@@ -159,7 +167,10 @@ BasePrintLibConvertValueToString (
     Buffer = BasePrintLibFillBuffer (Buffer, Width - Count, '0', Increment);\r
   }\r
 \r
-  Digits = 3 - (Count % 3);\r
+  Digits = Count % 3;\r
+  if (Digits != 0) {\r
+    Digits = 3 - Digits;\r
+  }\r
   for (Index = 0; Index < Count; Index++) {\r
     Buffer = BasePrintLibFillBuffer (Buffer, 1, ValueBuffer[Count - Index], Increment);\r
     if ((Flags & COMMA_TYPE) != 0) {\r
@@ -173,7 +184,7 @@ BasePrintLibConvertValueToString (
     }\r
   }\r
 \r
-  Buffer = BasePrintLibFillBuffer (Buffer, 1, 0, Increment);\r
+  BasePrintLibFillBuffer (Buffer, 1, 0, Increment);\r
 \r
   return ((Buffer - OriginalBuffer) / Increment);\r
 }\r