[edk2-devel] [Patch] BaseTools: Fix GCC compiler failure in new added tools.

Liming Gao posted 1 patch 4 years, 9 months ago
Failed in applying to current master (apply log)
There is a newer version of this series
BaseTools/Source/C/BfmLib/BfmLib.c                 | 2 +-
BaseTools/Source/C/FCE/BinaryParse.c               | 2 +-
BaseTools/Source/C/FMMT/FirmwareModuleManagement.c | 2 +-
BaseTools/Source/C/FMMT/FmmtLib.c                  | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
[edk2-devel] [Patch] BaseTools: Fix GCC compiler failure in new added tools.
Posted by Liming Gao 4 years, 9 months ago
From: gaozhic <zhichao.gao@intel.com>

GCC 7 or 8 reports some warnings in new added FCE/FMMT/BlmLib.

Signed-off-by: Liming Gao <liming.gao@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
---
 BaseTools/Source/C/BfmLib/BfmLib.c                 | 2 +-
 BaseTools/Source/C/FCE/BinaryParse.c               | 2 +-
 BaseTools/Source/C/FMMT/FirmwareModuleManagement.c | 2 +-
 BaseTools/Source/C/FMMT/FmmtLib.c                  | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/BaseTools/Source/C/BfmLib/BfmLib.c b/BaseTools/Source/C/BfmLib/BfmLib.c
index 9dedda3da2..5b7d5859fd 100644
--- a/BaseTools/Source/C/BfmLib/BfmLib.c
+++ b/BaseTools/Source/C/BfmLib/BfmLib.c
@@ -116,7 +116,7 @@ LibInitializeFvStruct (
 
   for (Index = 0; Index < MAX_NUMBER_OF_FILES_IN_FV; Index ++) {
     memset (Fv->FfsAttuibutes[Index].FfsName, '\0', _MAX_PATH);
-    memset (Fv->FfsAttuibutes[Index].UiName, '\0', _MAX_PATH);
+    memset (Fv->FfsAttuibutes[Index].UiName, '\0', _MAX_PATH * sizeof (CHAR16));
 
     Fv->FfsAttuibutes[Index].IsLeaf               = TRUE;
     Fv->FfsAttuibutes[Index].TotalSectionNum      = 0;
diff --git a/BaseTools/Source/C/FCE/BinaryParse.c b/BaseTools/Source/C/FCE/BinaryParse.c
index e9f8ee6826..3321963cb8 100644
--- a/BaseTools/Source/C/FCE/BinaryParse.c
+++ b/BaseTools/Source/C/FCE/BinaryParse.c
@@ -1240,7 +1240,7 @@ Done:
       ) {
         continue;
       }
-      sprintf (FileNameArry, "%s%c%s", FolderName, OS_SEP, pDirent->d_name);
+      snprintf (FileNameArry, MAX_FILENAME_LEN, FolderName, OS_SEP, pDirent->d_name);
       FfsFile = fopen (FileNameArry, "rb");
       Status = ReadFfsHeader (FfsFile, (UINT32 *)&FileSize);
       if (EFI_ERROR (Status)) {
diff --git a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c
index 63ae3c45a4..6648fbd54f 100644
--- a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c
+++ b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c
@@ -1572,7 +1572,7 @@ FmmtImageDelete (
                     // If decrease operation executed, we should adjust the ffs list. It will bring in more complex.
                     //
                     //FvInFd->FfsNumbers                    -= 1;
-                    memset(FvInFd->FfsAttuibutes[Index].UiName, '\0', _MAX_PATH);
+                    memset(FvInFd->FfsAttuibutes[Index].UiName, '\0', _MAX_PATH * sizeof (CHAR16));
                    if (FvInFd->FfsAttuibutes[Index].FvLevel > 1) {
                        for (j = Index - 1; j >= 0; j--) {
                            if (FvInFd->FfsAttuibutes[j].FvLevel == FvInFd->FfsAttuibutes[Index].FvLevel - 1) {
diff --git a/BaseTools/Source/C/FMMT/FmmtLib.c b/BaseTools/Source/C/FMMT/FmmtLib.c
index f87042114b..e477a52987 100644
--- a/BaseTools/Source/C/FMMT/FmmtLib.c
+++ b/BaseTools/Source/C/FMMT/FmmtLib.c
@@ -155,7 +155,7 @@ LibInitializeFvStruct (
 
   for (Index = 0; Index < MAX_NUMBER_OF_FILES_IN_FV; Index ++) {
     memset (Fv->FfsAttuibutes[Index].FfsName, '\0', _MAX_PATH);
-    memset (Fv->FfsAttuibutes[Index].UiName, '\0', _MAX_PATH);
+    memset (Fv->FfsAttuibutes[Index].UiName, '\0', _MAX_PATH * sizeof (CHAR16));
     memset (&Fv->FfsAttuibutes[Index].GuidName, '\0', sizeof(EFI_GUID));
     Fv->FfsAttuibutes[Index].UiNameSize           = 0;
     Fv->FfsAttuibutes[Index].IsLeaf               = TRUE;
-- 
2.13.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43343): https://edk2.groups.io/g/devel/message/43343
Mute This Topic: https://groups.io/mt/32315476/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [Patch] BaseTools: Fix GCC compiler failure in new added tools.
Posted by Philippe Mathieu-Daudé 4 years, 9 months ago
Hi,

On 7/5/19 9:51 AM, Liming Gao wrote:
> From: gaozhic <zhichao.gao@intel.com>
> 
> GCC 7 or 8 reports some warnings in new added FCE/FMMT/BlmLib.
> 
> Signed-off-by: Liming Gao <liming.gao@intel.com>
> Cc: Bob Feng <bob.c.feng@intel.com>
> ---
>  BaseTools/Source/C/BfmLib/BfmLib.c                 | 2 +-
>  BaseTools/Source/C/FCE/BinaryParse.c               | 2 +-
>  BaseTools/Source/C/FMMT/FirmwareModuleManagement.c | 2 +-
>  BaseTools/Source/C/FMMT/FmmtLib.c                  | 2 +-
>  4 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/BaseTools/Source/C/BfmLib/BfmLib.c b/BaseTools/Source/C/BfmLib/BfmLib.c
> index 9dedda3da2..5b7d5859fd 100644
> --- a/BaseTools/Source/C/BfmLib/BfmLib.c
> +++ b/BaseTools/Source/C/BfmLib/BfmLib.c
> @@ -116,7 +116,7 @@ LibInitializeFvStruct (
>  
>    for (Index = 0; Index < MAX_NUMBER_OF_FILES_IN_FV; Index ++) {
>      memset (Fv->FfsAttuibutes[Index].FfsName, '\0', _MAX_PATH);
> -    memset (Fv->FfsAttuibutes[Index].UiName, '\0', _MAX_PATH);
> +    memset (Fv->FfsAttuibutes[Index].UiName, '\0', _MAX_PATH * sizeof (CHAR16));

What about using wmemset() here? (I'm not sure it would be correct, I
just wonder).

>  
>      Fv->FfsAttuibutes[Index].IsLeaf               = TRUE;
>      Fv->FfsAttuibutes[Index].TotalSectionNum      = 0;
> diff --git a/BaseTools/Source/C/FCE/BinaryParse.c b/BaseTools/Source/C/FCE/BinaryParse.c
> index e9f8ee6826..3321963cb8 100644
> --- a/BaseTools/Source/C/FCE/BinaryParse.c
> +++ b/BaseTools/Source/C/FCE/BinaryParse.c
> @@ -1240,7 +1240,7 @@ Done:
>        ) {
>          continue;
>        }
> -      sprintf (FileNameArry, "%s%c%s", FolderName, OS_SEP, pDirent->d_name);
> +      snprintf (FileNameArry, MAX_FILENAME_LEN, FolderName, OS_SEP, pDirent->d_name);

You dropped the format string...

>        FfsFile = fopen (FileNameArry, "rb");
>        Status = ReadFfsHeader (FfsFile, (UINT32 *)&FileSize);
>        if (EFI_ERROR (Status)) {
> diff --git a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c
> index 63ae3c45a4..6648fbd54f 100644
> --- a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c
> +++ b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c
> @@ -1572,7 +1572,7 @@ FmmtImageDelete (
>                      // If decrease operation executed, we should adjust the ffs list. It will bring in more complex.
>                      //
>                      //FvInFd->FfsNumbers                    -= 1;
> -                    memset(FvInFd->FfsAttuibutes[Index].UiName, '\0', _MAX_PATH);
> +                    memset(FvInFd->FfsAttuibutes[Index].UiName, '\0', _MAX_PATH * sizeof (CHAR16));
>                     if (FvInFd->FfsAttuibutes[Index].FvLevel > 1) {
>                         for (j = Index - 1; j >= 0; j--) {
>                             if (FvInFd->FfsAttuibutes[j].FvLevel == FvInFd->FfsAttuibutes[Index].FvLevel - 1) {
> diff --git a/BaseTools/Source/C/FMMT/FmmtLib.c b/BaseTools/Source/C/FMMT/FmmtLib.c
> index f87042114b..e477a52987 100644
> --- a/BaseTools/Source/C/FMMT/FmmtLib.c
> +++ b/BaseTools/Source/C/FMMT/FmmtLib.c
> @@ -155,7 +155,7 @@ LibInitializeFvStruct (
>  
>    for (Index = 0; Index < MAX_NUMBER_OF_FILES_IN_FV; Index ++) {
>      memset (Fv->FfsAttuibutes[Index].FfsName, '\0', _MAX_PATH);
> -    memset (Fv->FfsAttuibutes[Index].UiName, '\0', _MAX_PATH);
> +    memset (Fv->FfsAttuibutes[Index].UiName, '\0', _MAX_PATH * sizeof (CHAR16));
>      memset (&Fv->FfsAttuibutes[Index].GuidName, '\0', sizeof(EFI_GUID));
>      Fv->FfsAttuibutes[Index].UiNameSize           = 0;
>      Fv->FfsAttuibutes[Index].IsLeaf               = TRUE;
> 

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43408): https://edk2.groups.io/g/devel/message/43408
Mute This Topic: https://groups.io/mt/32315476/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [Patch] BaseTools: Fix GCC compiler failure in new added tools.
Posted by Liming Gao 4 years, 9 months ago
Philippe:

>-----Original Message-----
>From: Philippe Mathieu-Daudé [mailto:philmd@redhat.com]
>Sent: Monday, July 08, 2019 11:49 PM
>To: devel@edk2.groups.io; Gao, Liming <liming.gao@intel.com>
>Cc: Gao, Zhichao <zhichao.gao@intel.com>; Feng, Bob C
><bob.c.feng@intel.com>
>Subject: Re: [edk2-devel] [Patch] BaseTools: Fix GCC compiler failure in new
>added tools.
>
>Hi,
>
>On 7/5/19 9:51 AM, Liming Gao wrote:
>> From: gaozhic <zhichao.gao@intel.com>
>>
>> GCC 7 or 8 reports some warnings in new added FCE/FMMT/BlmLib.
>>
>> Signed-off-by: Liming Gao <liming.gao@intel.com>
>> Cc: Bob Feng <bob.c.feng@intel.com>
>> ---
>>  BaseTools/Source/C/BfmLib/BfmLib.c                 | 2 +-
>>  BaseTools/Source/C/FCE/BinaryParse.c               | 2 +-
>>  BaseTools/Source/C/FMMT/FirmwareModuleManagement.c | 2 +-
>>  BaseTools/Source/C/FMMT/FmmtLib.c                  | 2 +-
>>  4 files changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/BaseTools/Source/C/BfmLib/BfmLib.c
>b/BaseTools/Source/C/BfmLib/BfmLib.c
>> index 9dedda3da2..5b7d5859fd 100644
>> --- a/BaseTools/Source/C/BfmLib/BfmLib.c
>> +++ b/BaseTools/Source/C/BfmLib/BfmLib.c
>> @@ -116,7 +116,7 @@ LibInitializeFvStruct (
>>
>>    for (Index = 0; Index < MAX_NUMBER_OF_FILES_IN_FV; Index ++) {
>>      memset (Fv->FfsAttuibutes[Index].FfsName, '\0', _MAX_PATH);
>> -    memset (Fv->FfsAttuibutes[Index].UiName, '\0', _MAX_PATH);
>> +    memset (Fv->FfsAttuibutes[Index].UiName, '\0', _MAX_PATH * sizeof
>(CHAR16));
>
>What about using wmemset() here? (I'm not sure it would be correct, I
>just wonder).
>
They should be same here. Here use memset to keep the same usage with others. 

>>
>>      Fv->FfsAttuibutes[Index].IsLeaf               = TRUE;
>>      Fv->FfsAttuibutes[Index].TotalSectionNum      = 0;
>> diff --git a/BaseTools/Source/C/FCE/BinaryParse.c
>b/BaseTools/Source/C/FCE/BinaryParse.c
>> index e9f8ee6826..3321963cb8 100644
>> --- a/BaseTools/Source/C/FCE/BinaryParse.c
>> +++ b/BaseTools/Source/C/FCE/BinaryParse.c
>> @@ -1240,7 +1240,7 @@ Done:
>>        ) {
>>          continue;
>>        }
>> -      sprintf (FileNameArry, "%s%c%s", FolderName, OS_SEP, pDirent-
>>d_name);
>> +      snprintf (FileNameArry, MAX_FILENAME_LEN, FolderName, OS_SEP,
>pDirent->d_name);
>
>You dropped the format string...
>
Good catch. I will fix it in next version. 

Thanks
Liming
>>        FfsFile = fopen (FileNameArry, "rb");
>>        Status = ReadFfsHeader (FfsFile, (UINT32 *)&FileSize);
>>        if (EFI_ERROR (Status)) {
>> diff --git a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c
>b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c
>> index 63ae3c45a4..6648fbd54f 100644
>> --- a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c
>> +++ b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c
>> @@ -1572,7 +1572,7 @@ FmmtImageDelete (
>>                      // If decrease operation executed, we should adjust the ffs list. It
>will bring in more complex.
>>                      //
>>                      //FvInFd->FfsNumbers                    -= 1;
>> -                    memset(FvInFd->FfsAttuibutes[Index].UiName, '\0',
>_MAX_PATH);
>> +                    memset(FvInFd->FfsAttuibutes[Index].UiName, '\0',
>_MAX_PATH * sizeof (CHAR16));
>>                     if (FvInFd->FfsAttuibutes[Index].FvLevel > 1) {
>>                         for (j = Index - 1; j >= 0; j--) {
>>                             if (FvInFd->FfsAttuibutes[j].FvLevel == FvInFd-
>>FfsAttuibutes[Index].FvLevel - 1) {
>> diff --git a/BaseTools/Source/C/FMMT/FmmtLib.c
>b/BaseTools/Source/C/FMMT/FmmtLib.c
>> index f87042114b..e477a52987 100644
>> --- a/BaseTools/Source/C/FMMT/FmmtLib.c
>> +++ b/BaseTools/Source/C/FMMT/FmmtLib.c
>> @@ -155,7 +155,7 @@ LibInitializeFvStruct (
>>
>>    for (Index = 0; Index < MAX_NUMBER_OF_FILES_IN_FV; Index ++) {
>>      memset (Fv->FfsAttuibutes[Index].FfsName, '\0', _MAX_PATH);
>> -    memset (Fv->FfsAttuibutes[Index].UiName, '\0', _MAX_PATH);
>> +    memset (Fv->FfsAttuibutes[Index].UiName, '\0', _MAX_PATH * sizeof
>(CHAR16));
>>      memset (&Fv->FfsAttuibutes[Index].GuidName, '\0', sizeof(EFI_GUID));
>>      Fv->FfsAttuibutes[Index].UiNameSize           = 0;
>>      Fv->FfsAttuibutes[Index].IsLeaf               = TRUE;
>>

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43415): https://edk2.groups.io/g/devel/message/43415
Mute This Topic: https://groups.io/mt/32315476/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-