[edk2] [PATCH 1/7] IntelFrameworkModulePkg: Replace [Ascii|Unicode]ValueToString

Hao Wu posted 7 patches 7 years, 8 months ago
[edk2] [PATCH 1/7] IntelFrameworkModulePkg: Replace [Ascii|Unicode]ValueToString
Posted by Hao Wu 7 years, 8 months ago
It is the follow up of commits 51f0ceb..9e32e97 to replace
AsciiValueToString/UnicodeValueToString with
AsciiValueToStringS/UnicodeValueToStringS.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jeff Fan <jeff.fan@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c     | 12 +++++++++---
 IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c | 20 +++++++++++++++++---
 IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c                | 15 +++++++++++----
 IntelFrameworkModulePkg/Universal/BdsDxe/MemoryTest.c               |  6 +++---
 4 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c
index a2e38d2..bdf2614 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c
@@ -1,7 +1,7 @@
 /** @file
 Dynamically update the pages.
 
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -844,11 +844,17 @@ UpdateConModePage (
     //
     // Build mode string Column x Row
     //
-    UnicodeValueToString (ModeString, 0, Col, 0);
+    UnicodeValueToStringS (ModeString, sizeof (ModeString), 0, Col, 0);
     PStr = &ModeString[0];
     StrCatS (PStr, ARRAY_SIZE (ModeString), L" x ");
     PStr = PStr + StrLen (PStr);
-    UnicodeValueToString (PStr , 0, Row, 0);
+    UnicodeValueToStringS (
+      PStr,
+      sizeof (ModeString) - ((UINTN)PStr - (UINTN)&ModeString[0]),
+      0,
+      Row,
+      0
+      );
 
     ModeToken[Index] = HiiSetString (CallbackData->BmmHiiHandle, 0, ModeString, NULL);
 
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c b/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
index af2b18a..125c49d 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
@@ -1,7 +1,7 @@
 /** @file
   The platform device manager reference implementation
 
-Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -388,7 +388,14 @@ GetMacAddressString(
   //
   HwAddress = &MacAddressNode->MacAddress.Addr[0];
   for (Index = 0; Index < HwAddressSize; Index++) {
-    String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *(HwAddress++), 2);
+    UnicodeValueToStringS (
+      String,
+      BufferLen - ((UINTN)String - (UINTN)*PBuffer),
+      PREFIX_ZERO | RADIX_HEX,
+      *(HwAddress++),
+      2
+      );
+    String += StrnLenS (String, (BufferLen - ((UINTN)String - (UINTN)*PBuffer)) / sizeof (CHAR16));
     if (Index < HwAddressSize - 1) {
       *String++ = L':';
     }
@@ -408,7 +415,14 @@ GetMacAddressString(
 
   if (VlanId != 0) {
     *String++ = L'\\';
-    String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, VlanId, 4);
+    UnicodeValueToStringS (
+      String,
+      BufferLen - ((UINTN)String - (UINTN)*PBuffer),
+      PREFIX_ZERO | RADIX_HEX,
+      VlanId,
+      4
+      );
+    String += StrnLenS (String, (BufferLen - ((UINTN)String - (UINTN)*PBuffer)) / sizeof (CHAR16));
   }
 
   //
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c b/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
index c771974..ec91422 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
@@ -1,7 +1,7 @@
 /** @file
   FrontPage routines to handle the callbacks and browser calls
 
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -629,9 +629,16 @@ ConvertProcessorToString (
 
   StringBuffer = AllocateZeroPool (0x20);
   ASSERT (StringBuffer != NULL);
-  Index = UnicodeValueToString (StringBuffer, LEFT_JUSTIFY, FreqMhz / 1000, 3);
+  UnicodeValueToStringS (StringBuffer, 0x20, LEFT_JUSTIFY, FreqMhz / 1000, 3);
+  Index = StrnLenS (StringBuffer, 0x20 / sizeof (CHAR16));
   StrCatS (StringBuffer, 0x20 / sizeof (CHAR16), L".");
-  UnicodeValueToString (StringBuffer + Index + 1, PREFIX_ZERO, (FreqMhz % 1000) / 10, 2);
+  UnicodeValueToStringS (
+    StringBuffer + Index + 1,
+    0x20 - sizeof (CHAR16) * (Index + 1),
+    PREFIX_ZERO,
+    (FreqMhz % 1000) / 10,
+    2
+    );
   StrCatS (StringBuffer, 0x20 / sizeof (CHAR16), L" GHz");
   *String = (CHAR16 *) StringBuffer;
   return ;
@@ -655,7 +662,7 @@ ConvertMemorySizeToString (
 
   StringBuffer = AllocateZeroPool (0x20);
   ASSERT (StringBuffer != NULL);
-  UnicodeValueToString (StringBuffer, LEFT_JUSTIFY, MemorySize, 6);
+  UnicodeValueToStringS (StringBuffer, 0x20, LEFT_JUSTIFY, MemorySize, 6);
   StrCatS (StringBuffer, 0x20 / sizeof (CHAR16), L" MB RAM");
 
   *String = (CHAR16 *) StringBuffer;
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/MemoryTest.c b/IntelFrameworkModulePkg/Universal/BdsDxe/MemoryTest.c
index 700e3e6..1188082 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/MemoryTest.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/MemoryTest.c
@@ -1,7 +1,7 @@
 /** @file
   Perform the platform memory test
 
-Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -318,7 +318,7 @@ BdsMemoryTest (
                               TempData
                               );
       if (TestPercent != PreviousValue) {
-        UnicodeValueToString (StrPercent, 0, TestPercent, 0);
+        UnicodeValueToStringS (StrPercent, sizeof (StrPercent), 0, TestPercent, 0);
         TmpStr = GetStringById (STRING_TOKEN (STR_MEMORY_TEST_PERCENT));
         if (TmpStr != NULL) {
           //
@@ -386,7 +386,7 @@ BdsMemoryTest (
 
 Done:
   if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) {
-    UnicodeValueToString (StrTotalMemory, COMMA_TYPE, TotalMemorySize, 0);
+    UnicodeValueToStringS (StrTotalMemory, StrTotalMemorySize, COMMA_TYPE, TotalMemorySize, 0);
     if (StrTotalMemory[0] == L',') {
       StrTotalMemory++;
       StrTotalMemorySize -= sizeof (CHAR16);
-- 
1.9.5.msysgit.0

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 1/7] IntelFrameworkModulePkg: Replace [Ascii|Unicode]ValueToString
Posted by Fan, Jeff 7 years, 8 months ago
Reviewed-by: Jeff Fan <jeff.fan@intel.com>

-----Original Message-----
From: Wu, Hao A 
Sent: Tuesday, February 21, 2017 7:35 PM
To: edk2-devel@lists.01.org
Cc: Wu, Hao A; Yao, Jiewen; Fan, Jeff
Subject: [PATCH 1/7] IntelFrameworkModulePkg: Replace [Ascii|Unicode]ValueToString

It is the follow up of commits 51f0ceb..9e32e97 to replace AsciiValueToString/UnicodeValueToString with AsciiValueToStringS/UnicodeValueToStringS.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jeff Fan <jeff.fan@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c     | 12 +++++++++---
 IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c | 20 +++++++++++++++++---
 IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c                | 15 +++++++++++----
 IntelFrameworkModulePkg/Universal/BdsDxe/MemoryTest.c               |  6 +++---
 4 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c
index a2e38d2..bdf2614 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c
@@ -1,7 +1,7 @@
 /** @file
 Dynamically update the pages.
 
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available under the terms and conditions of the BSD License  which accompanies this distribution.  The full text of the license may be found at @@ -844,11 +844,17 @@ UpdateConModePage (
     //
     // Build mode string Column x Row
     //
-    UnicodeValueToString (ModeString, 0, Col, 0);
+    UnicodeValueToStringS (ModeString, sizeof (ModeString), 0, Col, 0);
     PStr = &ModeString[0];
     StrCatS (PStr, ARRAY_SIZE (ModeString), L" x ");
     PStr = PStr + StrLen (PStr);
-    UnicodeValueToString (PStr , 0, Row, 0);
+    UnicodeValueToStringS (
+      PStr,
+      sizeof (ModeString) - ((UINTN)PStr - (UINTN)&ModeString[0]),
+      0,
+      Row,
+      0
+      );
 
     ModeToken[Index] = HiiSetString (CallbackData->BmmHiiHandle, 0, ModeString, NULL);
 
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c b/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
index af2b18a..125c49d 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.
+++ c
@@ -1,7 +1,7 @@
 /** @file
   The platform device manager reference implementation
 
-Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available under the terms and conditions of the BSD License  which accompanies this distribution.  The full text of the license may be found at @@ -388,7 +388,14 @@ GetMacAddressString(
   //
   HwAddress = &MacAddressNode->MacAddress.Addr[0];
   for (Index = 0; Index < HwAddressSize; Index++) {
-    String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *(HwAddress++), 2);
+    UnicodeValueToStringS (
+      String,
+      BufferLen - ((UINTN)String - (UINTN)*PBuffer),
+      PREFIX_ZERO | RADIX_HEX,
+      *(HwAddress++),
+      2
+      );
+    String += StrnLenS (String, (BufferLen - ((UINTN)String - 
+ (UINTN)*PBuffer)) / sizeof (CHAR16));
     if (Index < HwAddressSize - 1) {
       *String++ = L':';
     }
@@ -408,7 +415,14 @@ GetMacAddressString(
 
   if (VlanId != 0) {
     *String++ = L'\\';
-    String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, VlanId, 4);
+    UnicodeValueToStringS (
+      String,
+      BufferLen - ((UINTN)String - (UINTN)*PBuffer),
+      PREFIX_ZERO | RADIX_HEX,
+      VlanId,
+      4
+      );
+    String += StrnLenS (String, (BufferLen - ((UINTN)String - 
+ (UINTN)*PBuffer)) / sizeof (CHAR16));
   }
 
   //
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c b/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
index c771974..ec91422 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
@@ -1,7 +1,7 @@
 /** @file
   FrontPage routines to handle the callbacks and browser calls
 
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available under the terms and conditions of the BSD License  which accompanies this distribution.  The full text of the license may be found at @@ -629,9 +629,16 @@ ConvertProcessorToString (
 
   StringBuffer = AllocateZeroPool (0x20);
   ASSERT (StringBuffer != NULL);
-  Index = UnicodeValueToString (StringBuffer, LEFT_JUSTIFY, FreqMhz / 1000, 3);
+  UnicodeValueToStringS (StringBuffer, 0x20, LEFT_JUSTIFY, FreqMhz / 
+ 1000, 3);  Index = StrnLenS (StringBuffer, 0x20 / sizeof (CHAR16));
   StrCatS (StringBuffer, 0x20 / sizeof (CHAR16), L".");
-  UnicodeValueToString (StringBuffer + Index + 1, PREFIX_ZERO, (FreqMhz % 1000) / 10, 2);
+  UnicodeValueToStringS (
+    StringBuffer + Index + 1,
+    0x20 - sizeof (CHAR16) * (Index + 1),
+    PREFIX_ZERO,
+    (FreqMhz % 1000) / 10,
+    2
+    );
   StrCatS (StringBuffer, 0x20 / sizeof (CHAR16), L" GHz");
   *String = (CHAR16 *) StringBuffer;
   return ;
@@ -655,7 +662,7 @@ ConvertMemorySizeToString (
 
   StringBuffer = AllocateZeroPool (0x20);
   ASSERT (StringBuffer != NULL);
-  UnicodeValueToString (StringBuffer, LEFT_JUSTIFY, MemorySize, 6);
+  UnicodeValueToStringS (StringBuffer, 0x20, LEFT_JUSTIFY, MemorySize, 
+ 6);
   StrCatS (StringBuffer, 0x20 / sizeof (CHAR16), L" MB RAM");
 
   *String = (CHAR16 *) StringBuffer;
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/MemoryTest.c b/IntelFrameworkModulePkg/Universal/BdsDxe/MemoryTest.c
index 700e3e6..1188082 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/MemoryTest.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/MemoryTest.c
@@ -1,7 +1,7 @@
 /** @file
   Perform the platform memory test
 
-Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available under the terms and conditions of the BSD License  which accompanies this distribution.  The full text of the license may be found at @@ -318,7 +318,7 @@ BdsMemoryTest (
                               TempData
                               );
       if (TestPercent != PreviousValue) {
-        UnicodeValueToString (StrPercent, 0, TestPercent, 0);
+        UnicodeValueToStringS (StrPercent, sizeof (StrPercent), 0, 
+ TestPercent, 0);
         TmpStr = GetStringById (STRING_TOKEN (STR_MEMORY_TEST_PERCENT));
         if (TmpStr != NULL) {
           //
@@ -386,7 +386,7 @@ BdsMemoryTest (
 
 Done:
   if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) {
-    UnicodeValueToString (StrTotalMemory, COMMA_TYPE, TotalMemorySize, 0);
+    UnicodeValueToStringS (StrTotalMemory, StrTotalMemorySize, 
+ COMMA_TYPE, TotalMemorySize, 0);
     if (StrTotalMemory[0] == L',') {
       StrTotalMemory++;
       StrTotalMemorySize -= sizeof (CHAR16);
--
1.9.5.msysgit.0

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel