Revision: 16593
          http://sourceforge.net/p/edk2/code/16593
Author:   lgao4
Date:     2015-01-09 03:22:53 +0000 (Fri, 09 Jan 2015)
Log Message:
-----------
MdeModulePkg DxePrintLibPrint2Protocol Library SPrintLength() API issue.

SPrintLength() and SPrintLengthAsciiFormat() API doesn?\226?\128?\153t work 
with 'g', 't' and 'r' option. The fix sync from MdePkg BasePrintLib instance. 

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Liming Gao <liming....@intel.com>
Reviewed-by: Eric Dong <eric.d...@intel.com>

Modified Paths:
--------------
    trunk/edk2/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c

Modified: trunk/edk2/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
===================================================================
--- trunk/edk2/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c        
2015-01-09 02:38:39 UTC (rev 16592)
+++ trunk/edk2/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c        
2015-01-09 03:22:53 UTC (rev 16593)
@@ -6,7 +6,7 @@
   protocol related to this implementation, not in the public spec. So, this 
   library instance is only for this code base.
 
-Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -1076,8 +1076,8 @@
   return NumberOfPrinted;
 }
 
-#define WARNING_STATUS_NUMBER         4
-#define ERROR_STATUS_NUMBER           24
+#define WARNING_STATUS_NUMBER         5
+#define ERROR_STATUS_NUMBER           33
 
 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mStatusString[] = {
   "Success",                      //  RETURN_SUCCESS                = 0
@@ -1085,6 +1085,7 @@
   "Warning Delete Failure",       //  RETURN_WARN_DELETE_FAILURE    = 2
   "Warning Write Failure",        //  RETURN_WARN_WRITE_FAILURE     = 3
   "Warning Buffer Too Small",     //  RETURN_WARN_BUFFER_TOO_SMALL  = 4
+  "Warning Stale Data",           //  RETURN_WARN_STALE_DATA        = 5
   "Load Error",                   //  RETURN_LOAD_ERROR             = 1  | 
MAX_BIT
   "Invalid Parameter",            //  RETURN_INVALID_PARAMETER      = 2  | 
MAX_BIT
   "Unsupported",                  //  RETURN_UNSUPPORTED            = 3  | 
MAX_BIT
@@ -1108,10 +1109,57 @@
   "Aborted",                      //  RETURN_ABORTED                = 21 | 
MAX_BIT
   "ICMP Error",                   //  RETURN_ICMP_ERROR             = 22 | 
MAX_BIT
   "TFTP Error",                   //  RETURN_TFTP_ERROR             = 23 | 
MAX_BIT
-  "Protocol Error"                //  RETURN_PROTOCOL_ERROR         = 24 | 
MAX_BIT
+  "Protocol Error",               //  RETURN_PROTOCOL_ERROR         = 24 | 
MAX_BIT
+  "Incompatible Version",         //  RETURN_INCOMPATIBLE_VERSION   = 25 | 
MAX_BIT
+  "Security Violation",           //  RETURN_SECURITY_VIOLATION     = 26 | 
MAX_BIT
+  "CRC Error",                    //  RETURN_CRC_ERROR              = 27 | 
MAX_BIT
+  "End of Media",                 //  RETURN_END_OF_MEDIA           = 28 | 
MAX_BIT
+  "Reserved (29)",                //  RESERVED                      = 29 | 
MAX_BIT
+  "Reserved (30)",                //  RESERVED                      = 30 | 
MAX_BIT
+  "End of File",                  //  RETURN_END_OF_FILE            = 31 | 
MAX_BIT
+  "Invalid Language",             //  RETURN_INVALID_LANGUAGE       = 32 | 
MAX_BIT
+  "Compromised Data"              //  RETURN_COMPROMISED_DATA       = 33 | 
MAX_BIT
 };
 
 /**
+  Internal function that places the character into the Buffer.
+
+  Internal function that places ASCII or Unicode character into the Buffer.
+
+  @param  Buffer      The buffer to place the Unicode or ASCII string.
+  @param  EndBuffer   The end of the input Buffer. No characters will be
+                      placed after that. 
+  @param  Length      The count of character to be placed into Buffer.
+                      (Negative value indicates no buffer fill.)
+  @param  Character   The character to be placed into Buffer.
+  @param  Increment   The character increment in Buffer.
+
+  @return Buffer.
+
+**/
+CHAR8 *
+InternalPrintLibFillBuffer (
+  OUT CHAR8   *Buffer,
+  IN  CHAR8   *EndBuffer,
+  IN  INTN    Length,
+  IN  UINTN   Character,
+  IN  INTN    Increment
+  )
+{
+  INTN  Index;
+  
+  for (Index = 0; Index < Length && Buffer < EndBuffer; Index++) {
+    *Buffer = (CHAR8) Character;
+    if (Increment != 1) {
+      *(Buffer + 1) = (CHAR8)(Character >> 8);
+    }
+    Buffer += Increment;
+  }
+
+  return Buffer;
+}
+
+/**
   Worker function that produces a Null-terminated string in an output buffer 
   based on a Null-terminated format string and a VA_LIST argument list.
 
@@ -1149,6 +1197,7 @@
   IN  BASE_LIST    BaseListMarker  OPTIONAL
   )
 {
+  CHAR8             *OriginalBuffer;
   CHAR8             *EndBuffer;
   CHAR8             ValueBuffer[MAXIMUM_VALUE_CHARACTERS];
   UINT32            BytesPerOutputCharacter;
@@ -1185,7 +1234,19 @@
   // DxePrintLibPrint2Protocol (both PrintLib instances).
   //
 
-  ASSERT(Flags & COUNT_ONLY_NO_PRINT);
+  if ((Flags & COUNT_ONLY_NO_PRINT) != 0) {
+    if (BufferSize == 0) {
+      Buffer = NULL;
+    }
+  } else {
+    //
+    // We can run without a Buffer for counting only.
+    //
+    if (BufferSize == 0) {
+      return 0;
+    }
+    ASSERT (Buffer != NULL);
+  }
 
   if ((Flags & OUTPUT_UNICODE) != 0) {
     BytesPerOutputCharacter = 2;
@@ -1194,16 +1255,21 @@
   }
 
   LengthToReturn = 0;
+  EndBuffer = NULL;
+  OriginalBuffer = NULL;
 
   //
   // Reserve space for the Null terminator.
   //
-  BufferSize--;
+  if (Buffer != NULL) {
+    BufferSize--;
+    OriginalBuffer = Buffer;
 
-  //
-  // Set the tag for the end of the input Buffer.
-  //
-  EndBuffer      = Buffer + BufferSize * BytesPerOutputCharacter;
+    //
+    // Set the tag for the end of the input Buffer.
+    //
+    EndBuffer = Buffer + BufferSize * BytesPerOutputCharacter;
+  }
 
   if ((Flags & FORMAT_UNICODE) != 0) {
     //
@@ -1231,11 +1297,14 @@
   //
   // Loop until the end of the format string is reached or the output buffer 
is full
   //
-  while (FormatCharacter != 0 && Buffer < EndBuffer) {
+  while (FormatCharacter != 0) {
+    if ((Buffer != NULL) && (Buffer >= EndBuffer)) {
+      break;
+    }
     //
     // Clear all the flag bits except those that may have been passed in
     //
-    Flags &= (UINTN)(OUTPUT_UNICODE | FORMAT_UNICODE | COUNT_ONLY_NO_PRINT);
+    Flags &= (UINTN) (OUTPUT_UNICODE | FORMAT_UNICODE | COUNT_ONLY_NO_PRINT);
 
     //
     // Set the default width to zero, and the default precision to 1
@@ -1343,10 +1412,13 @@
         //
         // Flag space, +, 0, L & l are invalid for type p.
         //
-        Flags &= ~(UINTN)(PREFIX_BLANK | PREFIX_SIGN | PREFIX_ZERO | 
LONG_TYPE);
+        Flags &= ~((UINTN) (PREFIX_BLANK | PREFIX_SIGN | PREFIX_ZERO | 
LONG_TYPE));
         if (sizeof (VOID *) > 4) {
           Flags |= LONG_TYPE;
         }
+        //
+        // break skipped on purpose
+        //
       case 'X':
         Flags |= PREFIX_ZERO;
         //
@@ -1391,7 +1463,7 @@
         if ((Flags & RADIX_HEX) == 0) {
           Radix = 10;
           if (Comma) {
-            Flags &= (~(UINTN)PREFIX_ZERO);
+            Flags &= ~((UINTN) PREFIX_ZERO);
             Precision = 1;
           }
           if (Value < 0) {
@@ -1673,17 +1745,32 @@
     //
     if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) {
       LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);
+      if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
+        Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Width - 
Precision, ' ', BytesPerOutputCharacter);
+      }
     }
 
     if (ZeroPad) {
       if (Prefix != 0) {
         LengthToReturn += (1 * BytesPerOutputCharacter);
+        if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
+          Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, 
BytesPerOutputCharacter);
+        }
       }
       LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);
+      if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
+        Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Precision - 
Count, '0', BytesPerOutputCharacter);
+      }
     } else {
       LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);
+      if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
+        Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Precision - 
Count, ' ', BytesPerOutputCharacter);
+      }
       if (Prefix != 0) {
         LengthToReturn += (1 * BytesPerOutputCharacter);
+        if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
+          Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, 
BytesPerOutputCharacter);
+        }
       }
     }
 
@@ -1702,6 +1789,9 @@
       ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) 
<< 8)) & ArgumentMask;
 
       LengthToReturn += (1 * BytesPerOutputCharacter);
+      if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
+        Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, 
ArgumentCharacter, BytesPerOutputCharacter);
+      }
       ArgumentString    += BytesPerArgumentCharacter;
       Index++;
       if (Comma) {
@@ -1711,6 +1801,9 @@
           Index++;
           if (Index < Count) {
             LengthToReturn += (1 * BytesPerOutputCharacter);
+            if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
+              Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, ',', 
BytesPerOutputCharacter);
+            }
           }
         }
       }
@@ -1721,6 +1814,9 @@
     //
     if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | 
LEFT_JUSTIFY)) {
       LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);
+      if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
+        Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Width - 
Precision, ' ', BytesPerOutputCharacter);
+      }
     }
 
     //
@@ -1734,7 +1830,27 @@
     FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
   }
 
-  return (LengthToReturn / BytesPerOutputCharacter);
+  if ((Flags & COUNT_ONLY_NO_PRINT) != 0) {
+    return (LengthToReturn / BytesPerOutputCharacter);
+  }
+
+  ASSERT (Buffer != NULL);
+  //
+  // Null terminate the Unicode or ASCII string
+  //
+  InternalPrintLibFillBuffer (Buffer, EndBuffer + BytesPerOutputCharacter, 1, 
0, BytesPerOutputCharacter);
+  //
+  // Make sure output buffer cannot contain more than 
PcdMaximumUnicodeStringLength
+  // Unicode characters if PcdMaximumUnicodeStringLength is not zero. 
+  //
+  ASSERT ((((Flags & OUTPUT_UNICODE) == 0)) || (StrSize ((CHAR16 *) 
OriginalBuffer) != 0));
+  //
+  // Make sure output buffer cannot contain more than 
PcdMaximumAsciiStringLength
+  // ASCII characters if PcdMaximumAsciiStringLength is not zero. 
+  //
+  ASSERT ((((Flags & OUTPUT_UNICODE) != 0)) || (AsciiStrSize (OriginalBuffer) 
!= 0));
+
+  return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter);
 }
 
 /**


------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
edk2-commits mailing list
edk2-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to