]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/VolInfo: Fix printf issue using '%ls' in format string
authorHao Wu <hao.a.wu@intel.com>
Mon, 28 Nov 2016 07:18:20 +0000 (15:18 +0800)
committerHao Wu <hao.a.wu@intel.com>
Mon, 5 Dec 2016 01:48:28 +0000 (09:48 +0800)
https://bugzilla.tianocore.org/show_bug.cgi?id=257

For GCC compilers, when building with option '-fshort-wchar', wide char
string format '%ls' does not work properly for printf() function. The
string specified by '%ls' will not be printed.

This commit avoids using '%ls' for printf() function and converts the wide
char string to char string for printing.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/C/VolInfo/VolInfo.c

index 46c72123c87538f8457b4d8fd835c4a9a70edef1..71917afa25f8f110e7dd3ef816011d209f0fb250 100644 (file)
@@ -148,6 +148,65 @@ Usage (
   VOID\r
   );\r
 \r
+UINT32\r
+UnicodeStrLen (\r
+  IN CHAR16 *String\r
+  )\r
+  /*++\r
+\r
+  Routine Description:\r
+\r
+  Returns the length of a null-terminated unicode string.\r
+\r
+  Arguments:\r
+\r
+    String - The pointer to a null-terminated unicode string.\r
+\r
+  Returns:\r
+\r
+    N/A\r
+\r
+  --*/\r
+{\r
+  UINT32  Length;\r
+\r
+  for (Length = 0; *String != L'\0'; String++, Length++) {\r
+    ;\r
+  }\r
+  return Length;\r
+}\r
+\r
+VOID\r
+Unicode2AsciiString (\r
+  IN  CHAR16 *Source,\r
+  OUT CHAR8  *Destination\r
+  )\r
+  /*++\r
+\r
+  Routine Description:\r
+\r
+  Convert a null-terminated unicode string to a null-terminated ascii string.\r
+\r
+  Arguments:\r
+\r
+    Source      - The pointer to the null-terminated input unicode string.\r
+    Destination - The pointer to the null-terminated output ascii string.\r
+\r
+  Returns:\r
+\r
+    N/A\r
+\r
+  --*/\r
+{\r
+  while (*Source != '\0') {\r
+    *(Destination++) = (CHAR8) *(Source++);\r
+  }\r
+  //\r
+  // End the ascii with a NULL.\r
+  //\r
+  *Destination = '\0';\r
+}\r
+\r
 int\r
 main (\r
   int       argc,\r
@@ -1606,6 +1665,7 @@ Returns:
   UINT32              RealHdrLen;\r
   CHAR8               *ToolInputFileName;\r
   CHAR8               *ToolOutputFileName;\r
+  CHAR8               *UIFileName;\r
 \r
   ParsedLength = 0;\r
   ToolInputFileName = NULL;\r
@@ -1714,7 +1774,14 @@ Returns:
       break;\r
 \r
     case EFI_SECTION_USER_INTERFACE:\r
-      printf ("  String: %ls\n", (wchar_t *) &((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameString);\r
+      UIFileName = (CHAR8 *) malloc (UnicodeStrLen (((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameString) + 1);\r
+      if (UIFileName == NULL) {\r
+        Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      Unicode2AsciiString (((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameString, UIFileName);\r
+      printf ("  String: %s\n", UIFileName);\r
+      free (UIFileName);\r
       break;\r
 \r
     case EFI_SECTION_FIRMWARE_VOLUME_IMAGE:\r