]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BasePrintLib/PrintLib.c
1.Fix SetMem64.S to not use SSE3 instruction
[mirror_edk2.git] / MdePkg / Library / BasePrintLib / PrintLib.c
index 33da6cb6b07795e7f56ec7a56d0a868b2c495c61..455fd60526f4d894ef055c4db2e58286e7cddcad 100644 (file)
@@ -80,6 +80,7 @@ BasePrintLibVSPrint (
   )\r
 {\r
   CHAR8           *OriginalBuffer;\r
+  CHAR8           *EndBuffer;\r
   CHAR8           ValueBuffer[MAXIMUM_VALUE_CHARACTERS];\r
   UINTN           BytesPerOutputCharacter;\r
   UINTN           BytesPerFormatCharacter;\r
@@ -110,13 +111,22 @@ BasePrintLibVSPrint (
   }\r
   ASSERT (Buffer != NULL);\r
 \r
-  OriginalBuffer = Buffer;\r
-\r
   if ((Flags & OUTPUT_UNICODE) != 0) {\r
     BytesPerOutputCharacter = 2;\r
   } else {\r
     BytesPerOutputCharacter = 1;\r
   }\r
+\r
+  //\r
+  // Reserve space for the Null terminator.\r
+  //\r
+  BufferSize--;\r
+  OriginalBuffer = Buffer;\r
+  //\r
+  // Set the tag for the end of the input Buffer.\r
+  //\r
+  EndBuffer      = Buffer + BufferSize * BytesPerOutputCharacter;\r
+\r
   if ((Flags & FORMAT_UNICODE) != 0) {\r
     //\r
     // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength\r
@@ -135,10 +145,7 @@ BasePrintLibVSPrint (
     FormatMask = 0xff;\r
   }\r
 \r
-  //\r
-  // Reserve space for the Null terminator.\r
-  //\r
-  BufferSize--;\r
+\r
 \r
   //\r
   // Get the first character from the format string\r
@@ -148,7 +155,7 @@ BasePrintLibVSPrint (
   //\r
   // Loop until the end of the format string is reached or the output buffer is full\r
   //\r
-  while (FormatCharacter != 0 && BufferSize > 0) {\r
+  while (FormatCharacter != 0 && Buffer < EndBuffer) {\r
     //\r
     // Clear all the flag bits except those that may have been passed in\r
     //\r
@@ -244,13 +251,6 @@ BasePrintLibVSPrint (
         }\r
       } \r
 \r
-      //\r
-      // Limit the maximum field width to the remaining characters in the output buffer\r
-      //\r
-      if (Width > BufferSize) {\r
-        Width = BufferSize;\r
-      }\r
-\r
       //\r
       // Handle each argument type\r
       //\r
@@ -477,12 +477,6 @@ BasePrintLibVSPrint (
       }\r
     }\r
 \r
-    //\r
-    // Limit the length of the string to append to the remaining characters in the output buffer\r
-    //\r
-    if (Count > BufferSize) {\r
-      Count = BufferSize;\r
-    }\r
     if (Precision < Count) {\r
       Precision = Count;\r
     }\r
@@ -491,18 +485,18 @@ BasePrintLibVSPrint (
     // Pad before the string\r
     //\r
     if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) {\r
-      Buffer = BasePrintLibFillBuffer (Buffer, Width - Precision, ' ', BytesPerOutputCharacter);\r
+      Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);\r
     }\r
 \r
     if (ZeroPad) {\r
       if (Prefix != 0) {\r
-        Buffer = BasePrintLibFillBuffer (Buffer, 1, Prefix, BytesPerOutputCharacter);\r
+        Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);\r
       }\r
-      Buffer = BasePrintLibFillBuffer (Buffer, Precision - Count, '0', BytesPerOutputCharacter);\r
+      Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, '0', BytesPerOutputCharacter);\r
     } else {\r
-      Buffer = BasePrintLibFillBuffer (Buffer, Precision - Count, ' ', BytesPerOutputCharacter);\r
+      Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, ' ', BytesPerOutputCharacter);\r
       if (Prefix != 0) {\r
-        Buffer = BasePrintLibFillBuffer (Buffer, 1, Prefix, BytesPerOutputCharacter);\r
+        Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);\r
       }\r
     }\r
 \r
@@ -520,7 +514,7 @@ BasePrintLibVSPrint (
     while (Index < Count) {\r
       ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask;\r
 \r
-      Buffer = BasePrintLibFillBuffer (Buffer, 1, ArgumentCharacter, BytesPerOutputCharacter);\r
+      Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ArgumentCharacter, BytesPerOutputCharacter);\r
       ArgumentString    += BytesPerArgumentCharacter;\r
       Index++;\r
       if (Comma) {\r
@@ -529,7 +523,7 @@ BasePrintLibVSPrint (
           Digits = 0;\r
           Index++;\r
           if (Index < Count) {\r
-            Buffer = BasePrintLibFillBuffer (Buffer, 1, ',', BytesPerOutputCharacter);\r
+            Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ',', BytesPerOutputCharacter);\r
           }\r
         }\r
       }\r
@@ -539,14 +533,9 @@ BasePrintLibVSPrint (
     // Pad after the string\r
     //\r
     if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) {\r
-      Buffer = BasePrintLibFillBuffer (Buffer, Width - Precision, ' ', BytesPerOutputCharacter);\r
+      Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);\r
     }\r
 \r
-    //\r
-    // Reduce the number of characters\r
-    //\r
-    BufferSize -= Count;\r
-\r
     //\r
     // Get the next character from the format string\r
     //\r
@@ -561,7 +550,7 @@ BasePrintLibVSPrint (
   //\r
   // Null terminate the Unicode or ASCII string\r
   //\r
-  BasePrintLibFillBuffer (Buffer, 1, 0, BytesPerOutputCharacter);\r
+  BasePrintLibFillBuffer (Buffer, EndBuffer + BytesPerOutputCharacter, 1, 0, BytesPerOutputCharacter);\r
   //\r
   // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength\r
   // Unicode characters if PcdMaximumUnicodeStringLength is not zero. \r
@@ -999,7 +988,8 @@ AsciiSPrintUnicodeFormat (
                   Unicode string.\r
   @param  Flags   The bitmask of flags that specify left justification, zero pad, and commas.\r
   @param  Value   The 64-bit signed value to convert to a string.\r
-  @param  Width   The maximum number of Unicode characters to place in Buffer.\r
+  @param  Width   The maximum number of Unicode characters to place in Buffer, not including\r
+                  the Null-terminator.\r
   \r
   @return The number of Unicode characters in Buffer not including the Null-terminator.\r
 \r
@@ -1046,7 +1036,8 @@ UnicodeValueToString (
                   ASCII string.\r
   @param  Flags   The bitmask of flags that specify left justification, zero pad, and commas.\r
   @param  Value   The 64-bit signed value to convert to a string.\r
-  @param  Width   The maximum number of ASCII characters to place in Buffer.\r
+  @param  Width   The maximum number of ASCII characters to place in Buffer, not including\r
+                  the Null-terminator.\r
   \r
   @return The number of ASCII characters in Buffer not including the Null-terminator.\r
 \r