]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiLib/UefiLibPrint.c
Add Missing invocations to VA_END() for VA_START().
[mirror_edk2.git] / MdePkg / Library / UefiLib / UefiLibPrint.c
index 9dc3a5a200251e63ded9ea9c2ca37e3e675bff07..6eadc120c82021ad95d01ab11f0d17fbe9fc4752 100644 (file)
@@ -2,11 +2,11 @@
   Mde UEFI library API implementation.\r
   Print to StdErr or ConOut defined in EFI_SYSTEM_TABLE\r
 \r
-  Copyright (c) 2007 - 2009, Intel Corporation<BR>\r
-  All rights reserved. This program and the accompanying materials\r
+  Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
+  http://opensource.org/licenses/bsd-license.php.\r
 \r
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -45,12 +45,12 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = {
   If Format is NULL, then ASSERT().\r
   If Format is not aligned on a 16-bit boundary, then ASSERT().\r
 \r
-  @param Format   Null-terminated Unicode format string.\r
+  @param Format   Null-terminated Unicode format string.\r
   @param Console  The output console.\r
-  @param Marker   VA_LIST marker for the variable argument list.\r
+  @param Marker   VA_LIST marker for the variable argument list.\r
 \r
   @return The number of Unicode characters in the produced\r
-          output buffer not including the Null-terminator.\r
+          output buffer, not including the Null-terminator.\r
 **/\r
 UINTN\r
 InternalPrint (\r
@@ -59,12 +59,14 @@ InternalPrint (
   IN  VA_LIST                          Marker\r
   )\r
 {\r
-  UINTN   Return;\r
-  CHAR16  *Buffer;\r
-  UINTN   BufferSize;\r
+  EFI_STATUS  Status;\r
+  UINTN       Return;\r
+  CHAR16      *Buffer;\r
+  UINTN       BufferSize;\r
 \r
   ASSERT (Format != NULL);\r
   ASSERT (((UINTN) Format & BIT0) == 0);\r
+  ASSERT (Console != NULL);\r
 \r
   BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r
 \r
@@ -77,7 +79,10 @@ InternalPrint (
     //\r
     // To be extra safe make sure Console has been initialized\r
     //\r
-    Console->OutputString (Console, Buffer);\r
+    Status = Console->OutputString (Console, Buffer);\r
+    if (EFI_ERROR (Status)) {\r
+      Return = 0;\r
+    }\r
   }\r
 \r
   FreePool (Buffer);\r
@@ -96,12 +101,13 @@ InternalPrint (
   PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r
   If Format is NULL, then ASSERT().\r
   If Format is not aligned on a 16-bit boundary, then ASSERT().\r
+  If gST->ConOut is NULL, then ASSERT().\r
 \r
-  @param Format   Null-terminated Unicode format string.\r
-  @param ...      Variable argument list whose contents are accessed based \r
+  @param Format   Null-terminated Unicode format string.\r
+  @param ...      Variable argument list whose contents are accessed based \r
                   on the format string specified by Format.\r
   \r
-  @return Number of Unicode characters printed to ConOut.\r
+  @return The number of Unicode characters printed to ConOut.\r
 \r
 **/\r
 UINTN\r
@@ -134,12 +140,13 @@ Print (
   PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r
   If Format is NULL, then ASSERT().\r
   If Format is not aligned on a 16-bit boundary, then ASSERT().\r
+  If gST->StdErr is NULL, then ASSERT().\r
 \r
-  @param Format   Null-terminated Unicode format string.\r
+  @param Format   Null-terminated Unicode format string.\r
   @param ...      Variable argument list whose contents are accessed based \r
                   on the format string specified by Format.\r
   \r
-  @return Number of Unicode characters printed to StdErr.\r
+  @return The number of Unicode characters printed to StdErr.\r
 \r
 **/\r
 UINTN\r
@@ -173,7 +180,7 @@ ErrorPrint (
 \r
   If Format is NULL, then ASSERT().\r
 \r
-  @param Format   Null-terminated ASCII format string.\r
+  @param Format   Null-terminated ASCII format string.\r
   @param Console  The output console.\r
   @param Marker   VA_LIST marker for the variable argument list.\r
 \r
@@ -188,11 +195,13 @@ AsciiInternalPrint (
   IN  VA_LIST                          Marker\r
   )\r
 {\r
-  UINTN   Return;\r
-  CHAR16  *Buffer;\r
-  UINTN   BufferSize;\r
+  EFI_STATUS  Status;\r
+  UINTN       Return;\r
+  CHAR16      *Buffer;\r
+  UINTN       BufferSize;\r
 \r
   ASSERT (Format != NULL);\r
+  ASSERT (Console != NULL);\r
 \r
   BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r
 \r
@@ -205,7 +214,10 @@ AsciiInternalPrint (
     //\r
     // To be extra safe make sure Console has been initialized\r
     //\r
-    Console->OutputString (Console, Buffer);\r
+    Status = Console->OutputString (Console, Buffer);\r
+    if (EFI_ERROR (Status)) {\r
+      Return = 0;\r
+    }\r
   }\r
 \r
   FreePool (Buffer);\r
@@ -223,12 +235,13 @@ AsciiInternalPrint (
   string is greater than PcdUefiLibMaxPrintBufferSize, then only the first \r
   PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r
   If Format is NULL, then ASSERT().\r
+  If gST->ConOut is NULL, then ASSERT().\r
 \r
-  @param Format   Null-terminated ASCII format string.\r
+  @param Format   Null-terminated ASCII format string.\r
   @param ...      Variable argument list whose contents are accessed based \r
                   on the format string specified by Format.\r
   \r
-  @return Number of ASCII characters printed to ConOut.\r
+  @return The number of ASCII characters printed to ConOut.\r
 \r
 **/\r
 UINTN\r
@@ -261,12 +274,13 @@ AsciiPrint (
   string is greater than PcdUefiLibMaxPrintBufferSize, then only the first \r
   PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r
   If Format is NULL, then ASSERT().\r
+  If gST->StdErr is NULL, then ASSERT().\r
 \r
-  @param Format   Null-terminated ASCII format string.\r
+  @param Format   Null-terminated ASCII format string.\r
   @param ...      Variable argument list whose contents are accessed based \r
                   on the format string specified by Format.\r
   \r
-  @return Number of ASCII characters printed to ConErr.\r
+  @return The number of ASCII characters printed to ConErr.\r
 \r
 **/\r
 UINTN\r
@@ -306,8 +320,8 @@ AsciiErrorPrint (
   If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no\r
   string is printed, and 0 is returned.\r
 \r
-  @param  PointX       X coordinate to print the string.\r
-  @param  PointY       Y coordinate to print the string.\r
+  @param  PointX       An X coordinate to print the string.\r
+  @param  PointY       Y coordinate to print the string.\r
   @param  Foreground   The foreground color of the string being printed.  This is\r
                        an optional parameter that may be NULL.  If it is NULL,\r
                        then the foreground color of the current ConOut device\r
@@ -316,10 +330,10 @@ AsciiErrorPrint (
                        an optional parameter that may be NULL.  If it is NULL,\r
                        then the background color of the current ConOut device\r
                        in the EFI_SYSTEM_TABLE is used.\r
-  @param  Buffer       Null-terminated Unicode formatted string.\r
+  @param  Buffer       Null-terminated Unicode formatted string.\r
   @param  PrintNum     The number of Unicode formatted string to be printed.\r
 \r
-  @return  Number of Unicode Characters printed. Zero means no any character\r
+  @return  The number of Unicode Characters printed. Zero means no any character\r
            displayed successfully.\r
 \r
 **/\r
@@ -347,6 +361,9 @@ InternalPrintGraphic (
   EFI_UGA_DRAW_PROTOCOL               *UgaDraw;\r
   EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL     *Sto;\r
   EFI_HANDLE                          ConsoleHandle;\r
+  UINTN                               Width;\r
+  UINTN                               Height;\r
+  UINTN                               Delta;\r
 \r
   HorizontalResolution  = 0;\r
   VerticalResolution    = 0;\r
@@ -354,6 +371,8 @@ InternalPrintGraphic (
   RowInfoArray          = NULL;\r
 \r
   ConsoleHandle = gST->ConsoleOutHandle;\r
+  \r
+  ASSERT( ConsoleHandle != NULL);\r
 \r
   Status = gBS->HandleProtocol (\r
                   ConsoleHandle,\r
@@ -485,6 +504,15 @@ InternalPrintGraphic (
       //\r
       ASSERT (RowInfoArraySize <= 1);\r
 \r
+      if (RowInfoArraySize != 0) {\r
+        Width  = RowInfoArray[0].LineWidth;\r
+        Height = RowInfoArray[0].LineHeight;\r
+        Delta  = Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r
+      } else {\r
+        Width  = 0;\r
+        Height = 0;\r
+        Delta  = 0;\r
+      }\r
       Status = UgaDraw->Blt (\r
                           UgaDraw,\r
                           (EFI_UGA_PIXEL *) Blt->Image.Bitmap,\r
@@ -493,9 +521,9 @@ InternalPrintGraphic (
                           PointY,\r
                           PointX,\r
                           PointY,\r
-                          RowInfoArray[0].LineWidth,\r
-                          RowInfoArray[0].LineHeight,\r
-                          Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
+                          Width,\r
+                          Height,\r
+                          Delta\r
                           );\r
     } else {\r
       goto Error;\r
@@ -507,7 +535,11 @@ InternalPrintGraphic (
   //\r
   // Calculate the number of actual printed characters\r
   //\r
-  PrintNum = RowInfoArray[0].EndIndex - RowInfoArray[0].StartIndex + 1;\r
+  if (RowInfoArraySize != 0) {\r
+    PrintNum = RowInfoArray[0].EndIndex - RowInfoArray[0].StartIndex + 1;\r
+  } else {\r
+    PrintNum = 0;\r
+  }\r
 \r
   FreePool (RowInfoArray);\r
   FreePool (Blt);\r
@@ -542,9 +574,10 @@ Error:
   string is printed, and 0 is returned.\r
   If Format is NULL, then ASSERT().\r
   If Format is not aligned on a 16-bit boundary, then ASSERT().\r
+  If gST->ConsoleOutputHandle is NULL, then ASSERT().\r
 \r
-  @param  PointX       X coordinate to print the string.\r
-  @param  PointY       Y coordinate to print the string.\r
+  @param  PointX       An X coordinate to print the string.\r
+  @param  PointY       Y coordinate to print the string.\r
   @param  ForeGround   The foreground color of the string being printed.  This is\r
                        an optional parameter that may be NULL.  If it is NULL,\r
                        then the foreground color of the current ConOut device\r
@@ -553,9 +586,9 @@ Error:
                        an optional parameter that may be NULL.  If it is NULL, \r
                        then the background color of the current ConOut device\r
                        in the EFI_SYSTEM_TABLE is used.\r
-  @param  Format       Null-terminated Unicode format string.  See Print Library \r
+  @param  Format       Null-terminated Unicode format string.  See Print Library \r
                        for the supported format string syntax.\r
-  @param  ...          Variable argument list whose contents are accessed based on \r
+  @param  ...          Variable argument list whose contents are accessed based on \r
                        the format string specified by Format.         \r
 \r
   @return  The number of Unicode characters printed.\r
@@ -590,6 +623,8 @@ PrintXY (
 \r
   PrintNum = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);\r
 \r
+  VA_END (Marker);\r
+\r
   ReturnNum = InternalPrintGraphic (PointX, PointY, ForeGround, BackGround, Buffer, PrintNum);\r
 \r
   FreePool (Buffer);\r
@@ -618,9 +653,10 @@ PrintXY (
   If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no \r
   string is printed, and 0 is returned.\r
   If Format is NULL, then ASSERT().\r
+  If gST->ConsoleOutputHandle is NULL, then ASSERT().\r
 \r
-  @param  PointX       X coordinate to print the string.\r
-  @param  PointY       Y coordinate to print the string.\r
+  @param  PointX       An X coordinate to print the string.\r
+  @param  PointY       Y coordinate to print the string.\r
   @param  ForeGround   The foreground color of the string being printed.  This is\r
                        an optional parameter that may be NULL.  If it is NULL,\r
                        then the foreground color of the current ConOut device\r
@@ -629,7 +665,7 @@ PrintXY (
                        an optional parameter that may be NULL.  If it is NULL, \r
                        then the background color of the current ConOut device\r
                        in the EFI_SYSTEM_TABLE is used.\r
-  @param  Format       Null-terminated ASCII format string.  See Print Library \r
+  @param  Format       Null-terminated ASCII format string.  See Print Library \r
                        for the supported format string syntax.\r
   @param  ...          Variable argument list whose contents are accessed based on \r
                        the format string specified by Format.         \r
@@ -665,6 +701,8 @@ AsciiPrintXY (
 \r
   PrintNum = UnicodeSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);\r
 \r
+  VA_END (Marker);\r
+\r
   ReturnNum = InternalPrintGraphic (PointX, PointY, ForeGround, BackGround, Buffer, PrintNum);\r
 \r
   FreePool (Buffer);\r
@@ -672,3 +710,101 @@ AsciiPrintXY (
   return ReturnNum;\r
 }\r
 \r
+/** \r
+  Appends a formatted Unicode string to a Null-terminated Unicode string\r
\r
+  This function appends a formatted Unicode string to the Null-terminated \r
+  Unicode string specified by String.   String is optional and may be NULL.\r
+  Storage for the formatted Unicode string returned is allocated using \r
+  AllocatePool().  The pointer to the appended string is returned.  The caller\r
+  is responsible for freeing the returned string.\r
\r
+  If String is not NULL and not aligned on a 16-bit boundary, then ASSERT().\r
+  If FormatString is NULL, then ASSERT().\r
+  If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
\r
+  @param[in] String         A Null-terminated Unicode string.\r
+  @param[in] FormatString   A Null-terminated Unicode format string.\r
+  @param[in]  Marker        VA_LIST marker for the variable argument list.\r
+\r
+  @retval NULL    There was not enough available memory.\r
+  @return         Null-terminated Unicode string is that is the formatted \r
+                  string appended to String.\r
+**/\r
+CHAR16*\r
+EFIAPI\r
+CatVSPrint (\r
+  IN  CHAR16  *String, OPTIONAL\r
+  IN  CONST CHAR16  *FormatString,\r
+  IN  VA_LIST       Marker\r
+  )\r
+{\r
+  UINTN   CharactersRequired;\r
+  UINTN   SizeRequired;\r
+  CHAR16  *BufferToReturn;\r
+\r
+  CharactersRequired = SPrintLength(FormatString, Marker);\r
+\r
+  if (String != NULL) {\r
+    SizeRequired = StrSize(String) + (CharactersRequired * sizeof(CHAR16));\r
+  } else {\r
+    SizeRequired = sizeof(CHAR16) + (CharactersRequired * sizeof(CHAR16));\r
+  }\r
+\r
+  BufferToReturn = AllocateZeroPool(SizeRequired);\r
+\r
+  if (BufferToReturn == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  if (String != NULL) {\r
+    StrCpy(BufferToReturn, String);\r
+  }\r
+\r
+  UnicodeVSPrint(BufferToReturn + StrLen(BufferToReturn), (CharactersRequired+1) * sizeof(CHAR16), FormatString, Marker);\r
+\r
+  ASSERT(StrSize(BufferToReturn)==SizeRequired);\r
+\r
+  return (BufferToReturn);\r
+}\r
+\r
+/** \r
+  Appends a formatted Unicode string to a Null-terminated Unicode string\r
\r
+  This function appends a formatted Unicode string to the Null-terminated \r
+  Unicode string specified by String.   String is optional and may be NULL.\r
+  Storage for the formatted Unicode string returned is allocated using \r
+  AllocatePool().  The pointer to the appended string is returned.  The caller\r
+  is responsible for freeing the returned string.\r
\r
+  If String is not NULL and not aligned on a 16-bit boundary, then ASSERT().\r
+  If FormatString is NULL, then ASSERT().\r
+  If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
\r
+  @param[in] String         A Null-terminated Unicode string.\r
+  @param[in] FormatString   A Null-terminated Unicode format string.\r
+  @param[in] ...            The variable argument list whose contents are \r
+                            accessed based on the format string specified by \r
+                            FormatString.\r
+\r
+  @retval NULL    There was not enough available memory.\r
+  @return         Null-terminated Unicode string is that is the formatted \r
+                  string appended to String.\r
+**/\r
+CHAR16 *\r
+EFIAPI\r
+CatSPrint (\r
+  IN  CHAR16  *String, OPTIONAL\r
+  IN  CONST CHAR16  *FormatString,\r
+  ...\r
+  )\r
+{\r
+  VA_LIST   Marker;\r
+  CHAR16    *NewString;\r
+\r
+  VA_START (Marker, FormatString);\r
+  NewString = CatVSPrint(String, FormatString, Marker);\r
+  VA_END (Marker);\r
+  return NewString;\r
+}\r
+\r