From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E88A681F46 for ; Thu, 1 Dec 2016 18:55:56 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 01 Dec 2016 18:55:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,284,1477983600"; d="scan'208";a="1093479191" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga002.fm.intel.com with ESMTP; 01 Dec 2016 18:55:56 -0800 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.248.2; Thu, 1 Dec 2016 18:55:56 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.239]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.239]) with mapi id 14.03.0248.002; Fri, 2 Dec 2016 10:55:54 +0800 From: "Gao, Liming" To: "Wu, Hao A" , "edk2-devel@lists.01.org" Thread-Topic: [PATCH] BaseTools/VolInfo: Fix printf issue using '%ls' in format string Thread-Index: AQHSS9AIyeG6Cdj6pk+4SyuYLDCCM6Dz8pLQ Date: Fri, 2 Dec 2016 02:55:54 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14B4BC409@shsmsx102.ccr.corp.intel.com> References: <1480595992-23768-1-git-send-email-hao.a.wu@intel.com> In-Reply-To: <1480595992-23768-1-git-send-email-hao.a.wu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] BaseTools/VolInfo: Fix printf issue using '%ls' in format string X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Dec 2016 02:55:57 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hao: Place move UnicodeStrLen() and Unicode2AsciiString() implementation befo= re main() function. If so, they are not required to be declared again.=20 Other changes are good. Reviewed-by: Liming Gao Thanks Liming -----Original Message----- From: Wu, Hao A=20 Sent: Thursday, December 01, 2016 8:40 PM To: edk2-devel@lists.01.org Cc: Wu, Hao A ; Gao, Liming ; Zhu= , Yonghong Subject: [PATCH] BaseTools/VolInfo: Fix printf issue using '%ls' in format = string https://bugzilla.tianocore.org/show_bug.cgi?id=3D257 For GCC compilers, when building with option '-fshort-wchar', wide char str= ing format '%ls' does not work properly for printf() function. The string s= pecified 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 Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu --- BaseTools/Source/C/VolInfo/VolInfo.c | 79 ++++++++++++++++++++++++++++++++= +++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/BaseTools/Source/C/VolInfo/VolInfo.c b/BaseTools/Source/C/VolI= nfo/VolInfo.c index 46c7212..7d63e59 100644 --- a/BaseTools/Source/C/VolInfo/VolInfo.c +++ b/BaseTools/Source/C/VolInfo/VolInfo.c @@ -148,6 +148,17 @@ Usage ( VOID ); =20 +UINT32 +UnicodeStrLen ( + IN CHAR16 *String + ); + +VOID +Unicode2AsciiString ( + IN CHAR16 *Source, + OUT CHAR8 *Destination + ); + int main ( int argc, @@ -1606,6 +1617,7 @@ Returns: UINT32 RealHdrLen; CHAR8 *ToolInputFileName; CHAR8 *ToolOutputFileName; + CHAR8 *UIFileName; =20 ParsedLength =3D 0; ToolInputFileName =3D NULL; @@ -1714,7 +1726,14 @@ Returns: break; =20 case EFI_SECTION_USER_INTERFACE: - printf (" String: %ls\n", (wchar_t *) &((EFI_USER_INTERFACE_SECTION= *) Ptr)->FileNameString); + UIFileName =3D (CHAR8 *) malloc (UnicodeStrLen (((EFI_USER_INTERFACE= _SECTION *) Ptr)->FileNameString) + 1); + if (UIFileName =3D=3D NULL) { + Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!"); + return EFI_OUT_OF_RESOURCES; + } + Unicode2AsciiString (((EFI_USER_INTERFACE_SECTION *) Ptr)->FileNameS= tring, UIFileName); + printf (" String: %s\n", UIFileName); + free (UIFileName); break; =20 case EFI_SECTION_FIRMWARE_VOLUME_IMAGE: @@ -2360,3 +2379,61 @@ Returns: Reserved for future use\n"); } =20 +UINT32 +UnicodeStrLen ( + IN CHAR16 *String + ) + /*++ + + Routine Description: + + Returns the length of a null-terminated unicode string. + + Arguments: + + String - The pointer to a null-terminated unicode string. + + Returns: + + N/A + + --*/ +{ + UINT32 Length; + + for (Length =3D 0; *String !=3D L'\0'; String++, Length++) { + ; + } + return Length; +} + +VOID +Unicode2AsciiString ( + IN CHAR16 *Source, + OUT CHAR8 *Destination + ) + /*++ + + Routine Description: + + Convert a null-terminated unicode string to a null-terminated ascii stri= ng. + + Arguments: + + Source - The pointer to the null-terminated input unicode string. + Destination - The pointer to the null-terminated output ascii string. + + Returns: + + N/A + + --*/ +{ + while (*Source !=3D '\0') { + *(Destination++) =3D (CHAR8) *(Source++); + } + // + // End the ascii with a NULL. + // + *Destination =3D '\0'; +} -- 1.9.5.msysgit.0