From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 9D09F81F46 for ; Thu, 1 Dec 2016 19:02:39 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP; 01 Dec 2016 19:02:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,284,1477983600"; d="scan'208";a="198130708" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by fmsmga004.fm.intel.com with ESMTP; 01 Dec 2016 19:02:38 -0800 Received: from fmsmsx115.amr.corp.intel.com (10.18.116.19) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.248.2; Thu, 1 Dec 2016 19:02:38 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx115.amr.corp.intel.com (10.18.116.19) with Microsoft SMTP Server (TLS) id 14.3.248.2; Thu, 1 Dec 2016 19:02:38 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.142]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.218]) with mapi id 14.03.0248.002; Fri, 2 Dec 2016 11:02:36 +0800 From: "Wu, Hao A" To: "Gao, Liming" , "edk2-devel@lists.01.org" Thread-Topic: [PATCH] BaseTools/VolInfo: Fix printf issue using '%ls' in format string Thread-Index: AQHSS9AI6UaApd8uWES7IjKWsw9aRqDzcXUAgACHkgA= Date: Fri, 2 Dec 2016 03:02:35 +0000 Message-ID: References: <1480595992-23768-1-git-send-email-hao.a.wu@intel.com> <4A89E2EF3DFEDB4C8BFDE51014F606A14B4BC409@shsmsx102.ccr.corp.intel.com> In-Reply-To: <4A89E2EF3DFEDB4C8BFDE51014F606A14B4BC409@shsmsx102.ccr.corp.intel.com> Accept-Language: zh-CN, 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 03:02:39 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Got it. I will move those 2 implementation before main() before code check-in. Best Regards, Hao Wu > -----Original Message----- > From: Gao, Liming > Sent: Friday, December 02, 2016 10:56 AM > To: Wu, Hao A; edk2-devel@lists.01.org > Cc: Zhu, Yonghong > Subject: RE: [PATCH] BaseTools/VolInfo: Fix printf issue using '%ls' in f= ormat > string >=20 > Hao: > Place move UnicodeStrLen() and Unicode2AsciiString() implementation > before main() function. If so, they are not required to be declared again= . >=20 > Other changes are good. Reviewed-by: Liming Gao >=20 > Thanks > Liming > -----Original Message----- > From: Wu, Hao A > 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 forma= t > string >=20 > https://bugzilla.tianocore.org/show_bug.cgi?id=3D257 >=20 > For GCC compilers, when building with option '-fshort-wchar', wide char > string format '%ls' does not work properly for printf() function. The str= ing > specified by '%ls' will not be printed. >=20 > This commit avoids using '%ls' for printf() function and converts the wid= e char > string to char string for printing. >=20 > 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(-) >=20 > diff --git a/BaseTools/Source/C/VolInfo/VolInfo.c > b/BaseTools/Source/C/VolInfo/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_SECTI= ON *) > 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)- > >FileNameString, 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 st= ring. > + > + Arguments: > + > + Source - The pointer to the null-terminated input unicode strin= g. > + 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