]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/GenVtf & VolInfo: Fix build fail for 'snprintf' not defined
authorHao Wu <hao.a.wu@intel.com>
Tue, 28 Feb 2017 06:18:53 +0000 (14:18 +0800)
committerHao Wu <hao.a.wu@intel.com>
Wed, 1 Mar 2017 02:12:26 +0000 (10:12 +0800)
Function snprintf() is not supported in Visual Studio 2013 or older
version. The commit replaces the use of snprintf() with sprintf() to avoid
build failure for VS compilers.

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>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
BaseTools/Source/C/GenVtf/GenVtf.c
BaseTools/Source/C/VolInfo/VolInfo.c

index acc142a6d169a921796b1c11fecf2a3153e3427c..ff0e7cfb2c44b9a4b2afc9fc5078c40710584d85 100644 (file)
@@ -2,7 +2,7 @@
 This file contains functions required to generate a boot strap file (BSF) also \r
 known as the Volume Top File (VTF)\r
 \r
-Copyright (c) 1999 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 1999 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available \r
 under the terms and conditions of the BSD License which accompanies this \r
 distribution.  The full text of the license may be found at\r
@@ -1045,7 +1045,6 @@ Arguments:
 Returns:\r
 \r
   EFI_INVALID_PARAMETER  - The parameter is invalid\r
-  EFI_OUT_OF_RESOURCES   - Resource can not be allocated\r
   EFI_SUCCESS            - The function completed successfully\r
 \r
 --*/\r
@@ -1063,8 +1062,7 @@ Returns:
   CHAR8   Buff4[10];\r
   CHAR8   Buff5[10];\r
   CHAR8   Token[50];\r
-  CHAR8   *FormatString;\r
-  INTN    FormatLength;\r
+  CHAR8   FormatString[MAX_LINE_LEN];\r
 \r
   Fp = fopen (LongFilePath (VtfInfo->CompSymName), "rb");\r
 \r
@@ -1076,30 +1074,8 @@ Returns:
   //\r
   // Generate the format string for fscanf\r
   //\r
-  FormatLength = snprintf (\r
-                   NULL,\r
-                   0,\r
-                   "%%%us %%%us %%%us %%%us %%%us %%%us %%%us",\r
-                   (unsigned) sizeof (Buff1) - 1,\r
-                   (unsigned) sizeof (Buff2) - 1,\r
-                   (unsigned) sizeof (OffsetStr) - 1,\r
-                   (unsigned) sizeof (Buff3) - 1,\r
-                   (unsigned) sizeof (Buff4) - 1,\r
-                   (unsigned) sizeof (Buff5) - 1,\r
-                   (unsigned) sizeof (Token) - 1\r
-                   ) + 1;\r
-\r
-  FormatString = (CHAR8 *) malloc (FormatLength);\r
-  if (FormatString == NULL) {\r
-    fclose (Fp);\r
-\r
-    Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  snprintf (\r
+  sprintf (\r
     FormatString,\r
-    FormatLength,\r
     "%%%us %%%us %%%us %%%us %%%us %%%us %%%us",\r
     (unsigned) sizeof (Buff1) - 1,\r
     (unsigned) sizeof (Buff2) - 1,\r
@@ -1136,10 +1112,6 @@ Returns:
 \r
   memcpy ((VOID *) RelativeAddress, (VOID *) CompStartAddress, sizeof (UINT64));\r
 \r
-  if (FormatString != NULL) {\r
-    free (FormatString);\r
-  }\r
-\r
   if (Fp != NULL) {\r
     fclose (Fp);\r
   }\r
@@ -2242,8 +2214,7 @@ Returns:
   CHAR8   Section[MAX_LONG_FILE_PATH];\r
   CHAR8   Token[MAX_LONG_FILE_PATH];\r
   CHAR8   BaseToken[MAX_LONG_FILE_PATH];\r
-  CHAR8   *FormatString;\r
-  INTN    FormatLength;\r
+  CHAR8   FormatString[MAX_LINE_LEN];\r
   UINT64  TokenAddress;\r
   long    StartLocation;\r
 \r
@@ -2324,27 +2295,8 @@ Returns:
   //\r
   // Generate the format string for fscanf\r
   //\r
-  FormatLength = snprintf (\r
-                   NULL,\r
-                   0,\r
-                   "%%%us | %%%us | %%%us | %%%us\n",\r
-                   (unsigned) sizeof (Type) - 1,\r
-                   (unsigned) sizeof (Address) - 1,\r
-                   (unsigned) sizeof (Section) - 1,\r
-                   (unsigned) sizeof (Token) - 1\r
-                   ) + 1;\r
-\r
-  FormatString = (CHAR8 *) malloc (FormatLength);\r
-  if (FormatString == NULL) {\r
-    fclose (SourceFile);\r
-    fclose (DestFile);\r
-    Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
-    return EFI_ABORTED;\r
-  }\r
-\r
-  snprintf (\r
+  sprintf (\r
     FormatString,\r
-    FormatLength,\r
     "%%%us | %%%us | %%%us | %%%us\n",\r
     (unsigned) sizeof (Type) - 1,\r
     (unsigned) sizeof (Address) - 1,\r
@@ -2383,7 +2335,6 @@ Returns:
     }\r
   }\r
 \r
-  free (FormatString);\r
   fclose (SourceFile);\r
   fclose (DestFile);\r
   return EFI_SUCCESS;\r
index 71917afa25f8f110e7dd3ef816011d209f0fb250..2647cbb73a176c04b605f52ab661df272fa29438 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 The tool dumps the contents of a firmware volume\r
 \r
-Copyright (c) 1999 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 1999 - 2017, 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
@@ -2242,8 +2242,7 @@ Returns:
 {\r
   FILE              *Fptr;\r
   CHAR8             Line[MAX_LINE_LEN];\r
-  CHAR8             *FormatString;\r
-  INTN              FormatLength;\r
+  CHAR8             FormatString[MAX_LINE_LEN];\r
   GUID_TO_BASENAME  *GPtr;\r
 \r
   if ((Fptr = fopen (LongFilePath (FileName), "r")) == NULL) {\r
@@ -2254,23 +2253,8 @@ Returns:
   //\r
   // Generate the format string for fscanf\r
   //\r
-  FormatLength = snprintf (\r
-                   NULL,\r
-                   0,\r
-                   "%%%us %%%us",\r
-                   (unsigned) sizeof (GPtr->Guid) - 1,\r
-                   (unsigned) sizeof (GPtr->BaseName) - 1\r
-                   ) + 1;\r
-\r
-  FormatString = (CHAR8 *) malloc (FormatLength);\r
-  if (FormatString == NULL) {\r
-    fclose (Fptr);\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  snprintf (\r
+  sprintf (\r
     FormatString,\r
-    FormatLength,\r
     "%%%us %%%us",\r
     (unsigned) sizeof (GPtr->Guid) - 1,\r
     (unsigned) sizeof (GPtr->BaseName) - 1\r
@@ -2282,7 +2266,6 @@ Returns:
     //\r
     GPtr = malloc (sizeof (GUID_TO_BASENAME));\r
     if (GPtr == NULL) {\r
-      free (FormatString);\r
       fclose (Fptr);\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
@@ -2299,7 +2282,6 @@ Returns:
     }\r
   }\r
 \r
-  free (FormatString);\r
   fclose (Fptr);\r
   return EFI_SUCCESS;\r
 }\r