diff mbox

[edk2,5/6] ArmPkg/BdsLib: eliminate calls to deprecated string functions

Message ID 1477325206-24646-6-git-send-email-ard.biesheuvel@linaro.org
State Superseded
Headers show

Commit Message

Ard Biesheuvel Oct. 24, 2016, 4:06 p.m. UTC
Remove calls to deprecated string functions like AsciiStrCpy() and
UnicodeStrToAsciiStr()

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 ArmPkg/Library/BdsLib/BdsFilePath.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

-- 
2.7.4

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

Comments

Laszlo Ersek Oct. 25, 2016, 11:16 a.m. UTC | #1
On 10/24/16 18:06, Ard Biesheuvel wrote:
> Remove calls to deprecated string functions like AsciiStrCpy() and

> UnicodeStrToAsciiStr()

> 

> Contributed-under: TianoCore Contribution Agreement 1.0

> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> ---

>  ArmPkg/Library/BdsLib/BdsFilePath.c | 8 +++++---

>  1 file changed, 5 insertions(+), 3 deletions(-)

> 

> diff --git a/ArmPkg/Library/BdsLib/BdsFilePath.c b/ArmPkg/Library/BdsLib/BdsFilePath.c

> index aefeaed4ffb5..351a8bd8edf4 100644

> --- a/ArmPkg/Library/BdsLib/BdsFilePath.c

> +++ b/ArmPkg/Library/BdsLib/BdsFilePath.c

> @@ -964,7 +964,7 @@ Mtftp4CheckPacket (

>        Step      = (Context->DownloadedNbOfBytes   * TFTP_PROGRESS_SLIDER_STEPS) / Context->FileSize;

>        if (Step > LastStep) {

>          Print (mTftpProgressDelete);

> -        StrCpy (Progress, mTftpProgressFrame);

> +        StrCpyS (Progress, sizeof (Progress), mTftpProgressFrame);

>          for (Index = 1; Index < Step; Index++) {

>            Progress[Index] = L'=';

>          }


Same problem; please use CopyMem(), or introduce an ARRAY_SIZE() macro,
and use that (which divides by the size of the element at offset zero).

> @@ -1044,6 +1044,7 @@ BdsTftpLoadImage (

>    UINT64                   FileSize;

>    UINT64                   TftpBufferSize;

>    BDS_TFTP_CONTEXT         *TftpContext;

> +  UINTN                    PathNameLen;

>  

>    ASSERT(IS_DEVICE_PATH_NODE (RemainingDevicePath, MESSAGING_DEVICE_PATH, MSG_IPv4_DP));

>    IPv4DevicePathNode = (IPv4_DEVICE_PATH*)RemainingDevicePath;

> @@ -1187,8 +1188,9 @@ BdsTftpLoadImage (

>  

>    // The Device Path might contain multiple FilePath nodes

>    PathName      = ConvertDevicePathToText ((EFI_DEVICE_PATH_PROTOCOL*)(IPv4DevicePathNode + 1), FALSE, FALSE);

> -  AsciiFilePath = AllocatePool (StrLen (PathName) + 1);

> -  UnicodeStrToAsciiStr (PathName, AsciiFilePath);

> +  PathNameLen   = StrLen (PathName) + 1;

> +  AsciiFilePath = AllocatePool (PathNameLen);

> +  UnicodeStrToAsciiStrS (PathName, AsciiFilePath, PathNameLen);

>  

>    //

>    // Try to get the size of the file in bytes from the server. If it fails,

> 


This hunk looks fine.

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

Patch

diff --git a/ArmPkg/Library/BdsLib/BdsFilePath.c b/ArmPkg/Library/BdsLib/BdsFilePath.c
index aefeaed4ffb5..351a8bd8edf4 100644
--- a/ArmPkg/Library/BdsLib/BdsFilePath.c
+++ b/ArmPkg/Library/BdsLib/BdsFilePath.c
@@ -964,7 +964,7 @@  Mtftp4CheckPacket (
       Step      = (Context->DownloadedNbOfBytes   * TFTP_PROGRESS_SLIDER_STEPS) / Context->FileSize;
       if (Step > LastStep) {
         Print (mTftpProgressDelete);
-        StrCpy (Progress, mTftpProgressFrame);
+        StrCpyS (Progress, sizeof (Progress), mTftpProgressFrame);
         for (Index = 1; Index < Step; Index++) {
           Progress[Index] = L'=';
         }
@@ -1044,6 +1044,7 @@  BdsTftpLoadImage (
   UINT64                   FileSize;
   UINT64                   TftpBufferSize;
   BDS_TFTP_CONTEXT         *TftpContext;
+  UINTN                    PathNameLen;
 
   ASSERT(IS_DEVICE_PATH_NODE (RemainingDevicePath, MESSAGING_DEVICE_PATH, MSG_IPv4_DP));
   IPv4DevicePathNode = (IPv4_DEVICE_PATH*)RemainingDevicePath;
@@ -1187,8 +1188,9 @@  BdsTftpLoadImage (
 
   // The Device Path might contain multiple FilePath nodes
   PathName      = ConvertDevicePathToText ((EFI_DEVICE_PATH_PROTOCOL*)(IPv4DevicePathNode + 1), FALSE, FALSE);
-  AsciiFilePath = AllocatePool (StrLen (PathName) + 1);
-  UnicodeStrToAsciiStr (PathName, AsciiFilePath);
+  PathNameLen   = StrLen (PathName) + 1;
+  AsciiFilePath = AllocatePool (PathNameLen);
+  UnicodeStrToAsciiStrS (PathName, AsciiFilePath, PathNameLen);
 
   //
   // Try to get the size of the file in bytes from the server. If it fails,