From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 4C94581EDE for ; Tue, 28 Feb 2017 02:36:38 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP; 28 Feb 2017 02:36:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,219,1484035200"; d="scan'208";a="71038268" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by fmsmga006.fm.intel.com with ESMTP; 28 Feb 2017 02:36:37 -0800 Received: from fmsmsx151.amr.corp.intel.com (10.18.125.4) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 28 Feb 2017 02:36:37 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX151.amr.corp.intel.com (10.18.125.4) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 28 Feb 2017 02:36:30 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.20]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.132]) with mapi id 14.03.0248.002; Tue, 28 Feb 2017 18:36:28 +0800 From: "Zhu, Yonghong" To: "Wu, Hao A" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Zhu, Yonghong" Thread-Topic: [PATCH] BaseTools/GenVtf & VolInfo: Fix build fail for 'snprintf' not defined Thread-Index: AQHSkZhXmUDhBTuh1USHGPPNT24pHKF+ObtQ Date: Tue, 28 Feb 2017 10:36:27 +0000 Message-ID: References: <1488268645-18140-1-git-send-email-hao.a.wu@intel.com> In-Reply-To: <1488268645-18140-1-git-send-email-hao.a.wu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZWY3YTIwMGMtMDRkOC00NmEzLTk5YzUtZmRhNDA3YjQ4NzFjIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6IkVycWZIR2k3RStocUQrUzNGUzdtUlVraTRPeE1oVlRFUzg0QllKcUg4Qjg9In0= x-ctpclassification: CTP_IC x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] BaseTools/GenVtf & VolInfo: Fix build fail for 'snprintf' not defined 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: Tue, 28 Feb 2017 10:36:38 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Yonghong Zhu =20 Best Regards, Zhu Yonghong -----Original Message----- From: Wu, Hao A=20 Sent: Tuesday, February 28, 2017 3:57 PM To: edk2-devel@lists.01.org Cc: Wu, Hao A ; Zhu, Yonghong ;= Gao, Liming Subject: [PATCH] BaseTools/GenVtf & VolInfo: Fix build fail for 'snprintf' = not defined Function snprintf() is not supported in Visual Studio 2013 or older version= . The commit replaces the use of snprintf() with sprintf() to avoid build f= ailure for VS compilers. Cc: Yonghong Zhu Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu --- BaseTools/Source/C/GenVtf/GenVtf.c | 59 +++-----------------------------= ---- BaseTools/Source/C/VolInfo/VolInfo.c | 24 ++------------- 2 files changed, 8 insertions(+), 75 deletions(-) diff --git a/BaseTools/Source/C/GenVtf/GenVtf.c b/BaseTools/Source/C/GenVtf= /GenVtf.c index acc142a..ff0e7cf 100644 --- a/BaseTools/Source/C/GenVtf/GenVtf.c +++ b/BaseTools/Source/C/GenVtf/GenVtf.c @@ -2,7 +2,7 @@ This file contains functions required to generate a boot strap file (BSF) = also known as the Volume Top File (VTF) =20 -Copyright (c) 1999 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 1999 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made availabl= e under the terms and conditions of the BSD License which accompanies this= distribution. The full text of the license may be found at @@ -1045,7 +1= 045,6 @@ Arguments: Returns: =20 EFI_INVALID_PARAMETER - The parameter is invalid - EFI_OUT_OF_RESOURCES - Resource can not be allocated EFI_SUCCESS - The function completed successfully =20 --*/ @@ -1063,8 +1062,7 @@ Returns: CHAR8 Buff4[10]; CHAR8 Buff5[10]; CHAR8 Token[50]; - CHAR8 *FormatString; - INTN FormatLength; + CHAR8 FormatString[MAX_LINE_LEN]; =20 Fp =3D fopen (LongFilePath (VtfInfo->CompSymName), "rb"); =20 @@ -1076,30 +1074,8 @@ Returns: // // Generate the format string for fscanf // - FormatLength =3D snprintf ( - NULL, - 0, - "%%%us %%%us %%%us %%%us %%%us %%%us %%%us", - (unsigned) sizeof (Buff1) - 1, - (unsigned) sizeof (Buff2) - 1, - (unsigned) sizeof (OffsetStr) - 1, - (unsigned) sizeof (Buff3) - 1, - (unsigned) sizeof (Buff4) - 1, - (unsigned) sizeof (Buff5) - 1, - (unsigned) sizeof (Token) - 1 - ) + 1; - - FormatString =3D (CHAR8 *) malloc (FormatLength); - if (FormatString =3D=3D NULL) { - fclose (Fp); - - Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!"); - return EFI_OUT_OF_RESOURCES; - } - - snprintf ( + sprintf ( FormatString, - FormatLength, "%%%us %%%us %%%us %%%us %%%us %%%us %%%us", (unsigned) sizeof (Buff1) - 1, (unsigned) sizeof (Buff2) - 1, @@ -1136,10 +1112,6 @@ Returns: =20 memcpy ((VOID *) RelativeAddress, (VOID *) CompStartAddress, sizeof (UIN= T64)); =20 - if (FormatString !=3D NULL) { - free (FormatString); - } - if (Fp !=3D NULL) { fclose (Fp); } @@ -2242,8 +2214,7 @@ Returns: CHAR8 Section[MAX_LONG_FILE_PATH]; CHAR8 Token[MAX_LONG_FILE_PATH]; CHAR8 BaseToken[MAX_LONG_FILE_PATH]; - CHAR8 *FormatString; - INTN FormatLength; + CHAR8 FormatString[MAX_LINE_LEN]; UINT64 TokenAddress; long StartLocation; =20 @@ -2324,27 +2295,8 @@ Returns: // // Generate the format string for fscanf // - FormatLength =3D snprintf ( - NULL, - 0, - "%%%us | %%%us | %%%us | %%%us\n", - (unsigned) sizeof (Type) - 1, - (unsigned) sizeof (Address) - 1, - (unsigned) sizeof (Section) - 1, - (unsigned) sizeof (Token) - 1 - ) + 1; - - FormatString =3D (CHAR8 *) malloc (FormatLength); - if (FormatString =3D=3D NULL) { - fclose (SourceFile); - fclose (DestFile); - Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!"); - return EFI_ABORTED; - } - - snprintf ( + sprintf ( FormatString, - FormatLength, "%%%us | %%%us | %%%us | %%%us\n", (unsigned) sizeof (Type) - 1, (unsigned) sizeof (Address) - 1, @@ -2383,7 +2335,6 @@ Returns: } } =20 - free (FormatString); fclose (SourceFile); fclose (DestFile); return EFI_SUCCESS; diff --git a/BaseTools/Source/C/VolInfo/VolInfo.c b/BaseTools/Source/C/VolI= nfo/VolInfo.c index 71917af..2647cbb 100644 --- a/BaseTools/Source/C/VolInfo/VolInfo.c +++ b/BaseTools/Source/C/VolInfo/VolInfo.c @@ -1,7 +1,7 @@ /** @file The tool dumps the contents of a firmware volume =20 -Copyright (c) 1999 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 1999 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made availab= le under the terms and conditions of the BSD License which accompanies thi= s distribution. The full text of the license may be found at @@ -2242,8 +2= 242,7 @@ Returns: { FILE *Fptr; CHAR8 Line[MAX_LINE_LEN]; - CHAR8 *FormatString; - INTN FormatLength; + CHAR8 FormatString[MAX_LINE_LEN]; GUID_TO_BASENAME *GPtr; =20 if ((Fptr =3D fopen (LongFilePath (FileName), "r")) =3D=3D NULL) { @@ -2= 254,23 +2253,8 @@ Returns: // // Generate the format string for fscanf // - FormatLength =3D snprintf ( - NULL, - 0, - "%%%us %%%us", - (unsigned) sizeof (GPtr->Guid) - 1, - (unsigned) sizeof (GPtr->BaseName) - 1 - ) + 1; - - FormatString =3D (CHAR8 *) malloc (FormatLength); - if (FormatString =3D=3D NULL) { - fclose (Fptr); - return EFI_OUT_OF_RESOURCES; - } - - snprintf ( + sprintf ( FormatString, - FormatLength, "%%%us %%%us", (unsigned) sizeof (GPtr->Guid) - 1, (unsigned) sizeof (GPtr->BaseName) - 1 @@ -2282,7 +2266,6 @@ Returns: // GPtr =3D malloc (sizeof (GUID_TO_BASENAME)); if (GPtr =3D=3D NULL) { - free (FormatString); fclose (Fptr); return EFI_OUT_OF_RESOURCES; } @@ -2299,7 +2282,6 @@ Returns: } } =20 - free (FormatString); fclose (Fptr); return EFI_SUCCESS; } -- 1.9.5.msysgit.0