[edk2-devel] [PATCH] BaseTools/GenFw: Fix casting result of comparison

Tim Crawford posted 1 patch 3 years, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/edk2 tags/patchew/b6c292f00d6559178af51068c319c18615f84ae3.1616714759.git.crawfxrd@gmail.com
BaseTools/Source/C/GenFw/Elf32Convert.c | 2 +-
BaseTools/Source/C/GenFw/Elf64Convert.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
[edk2-devel] [PATCH] BaseTools/GenFw: Fix casting result of comparison
Posted by Tim Crawford 3 years, 1 month ago
The cast in IsDataShdr() is only applied the left side, causing it to
always return FALSE.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3271
Signed-off-by: Tim Crawford <tcrawford@system76.com>
---
 BaseTools/Source/C/GenFw/Elf32Convert.c | 2 +-
 BaseTools/Source/C/GenFw/Elf64Convert.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Source/C/GenFw/Elf32Convert.c b/BaseTools/Source/C/GenFw/Elf32Convert.c
index 7f351287a9..df54991768 100644
--- a/BaseTools/Source/C/GenFw/Elf32Convert.c
+++ b/BaseTools/Source/C/GenFw/Elf32Convert.c
@@ -262,7 +262,7 @@ IsDataShdr (
   if (IsHiiRsrcShdr(Shdr)) {
     return FALSE;
   }
-  return (BOOLEAN) (Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) == (SHF_ALLOC | SHF_WRITE);
+  return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) == (SHF_ALLOC | SHF_WRITE));
 }
 
 STATIC
diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c
index 4ed6b4477e..1bf1e9accb 100644
--- a/BaseTools/Source/C/GenFw/Elf64Convert.c
+++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
@@ -270,7 +270,7 @@ IsDataShdr (
   if (IsHiiRsrcShdr(Shdr)) {
     return FALSE;
   }
-  return (BOOLEAN) (Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) == (SHF_ALLOC | SHF_WRITE);
+  return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) == (SHF_ALLOC | SHF_WRITE));
 }
 
 STATIC
-- 
2.30.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#73394): https://edk2.groups.io/g/devel/message/73394
Mute This Topic: https://groups.io/mt/81630142/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


回复: [edk2-devel] [PATCH] BaseTools/GenFw: Fix casting result of comparison
Posted by gaoliming 3 years ago
Tim:
 This change is good. Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>

 Besides, which compiler detects this issue?

Thanks
Liming
> -----邮件原件-----
> 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Tim Crawford
> 发送时间: 2021年3月26日 8:48
> 收件人: devel@edk2.groups.io
> 主题: [edk2-devel] [PATCH] BaseTools/GenFw: Fix casting result of
> comparison
> 
> The cast in IsDataShdr() is only applied the left side, causing it to
> always return FALSE.
> 
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3271
> Signed-off-by: Tim Crawford <tcrawford@system76.com>
> ---
>  BaseTools/Source/C/GenFw/Elf32Convert.c | 2 +-
>  BaseTools/Source/C/GenFw/Elf64Convert.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/BaseTools/Source/C/GenFw/Elf32Convert.c
> b/BaseTools/Source/C/GenFw/Elf32Convert.c
> index 7f351287a9..df54991768 100644
> --- a/BaseTools/Source/C/GenFw/Elf32Convert.c
> +++ b/BaseTools/Source/C/GenFw/Elf32Convert.c
> @@ -262,7 +262,7 @@ IsDataShdr (
>    if (IsHiiRsrcShdr(Shdr)) {
> 
>      return FALSE;
> 
>    }
> 
> -  return (BOOLEAN) (Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
> (SHF_ALLOC | SHF_WRITE);
> 
> +  return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
> (SHF_ALLOC | SHF_WRITE));
> 
>  }
> 
> 
> 
>  STATIC
> 
> diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c
> b/BaseTools/Source/C/GenFw/Elf64Convert.c
> index 4ed6b4477e..1bf1e9accb 100644
> --- a/BaseTools/Source/C/GenFw/Elf64Convert.c
> +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
> @@ -270,7 +270,7 @@ IsDataShdr (
>    if (IsHiiRsrcShdr(Shdr)) {
> 
>      return FALSE;
> 
>    }
> 
> -  return (BOOLEAN) (Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
> (SHF_ALLOC | SHF_WRITE);
> 
> +  return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
> (SHF_ALLOC | SHF_WRITE));
> 
>  }
> 
> 
> 
>  STATIC
> 
> --
> 2.30.2
> 
> 
> 
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> View/Reply Online (#73394): https://edk2.groups.io/g/devel/message/73394
> Mute This Topic: https://groups.io/mt/81630142/4905953
> Group Owner: devel+owner@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub
> [gaoliming@byosoft.com.cn]
> -=-=-=-=-=-=
> 





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#73505): https://edk2.groups.io/g/devel/message/73505
Mute This Topic: https://groups.io/mt/81689681/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH] BaseTools/GenFw: Fix casting result of comparison
Posted by Tim Crawford 3 years ago
This was detected while attempting to use C99's stdbool for the
BOOLEAN type, which causes a compilation error. But I am using GCC10.

On Sun, Mar 28, 2021 at 11:11 PM gaoliming <gaoliming@byosoft.com.cn> wrote:
>
> Tim:
>  This change is good. Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
>
>  Besides, which compiler detects this issue?
>
> Thanks
> Liming
> > -----邮件原件-----
> > 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Tim Crawford
> > 发送时间: 2021年3月26日 8:48
> > 收件人: devel@edk2.groups.io
> > 主题: [edk2-devel] [PATCH] BaseTools/GenFw: Fix casting result of
> > comparison
> >
> > The cast in IsDataShdr() is only applied the left side, causing it to
> > always return FALSE.
> >
> > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3271
> > Signed-off-by: Tim Crawford <tcrawford@system76.com>
> > ---
> >  BaseTools/Source/C/GenFw/Elf32Convert.c | 2 +-
> >  BaseTools/Source/C/GenFw/Elf64Convert.c | 2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/BaseTools/Source/C/GenFw/Elf32Convert.c
> > b/BaseTools/Source/C/GenFw/Elf32Convert.c
> > index 7f351287a9..df54991768 100644
> > --- a/BaseTools/Source/C/GenFw/Elf32Convert.c
> > +++ b/BaseTools/Source/C/GenFw/Elf32Convert.c
> > @@ -262,7 +262,7 @@ IsDataShdr (
> >    if (IsHiiRsrcShdr(Shdr)) {
> >
> >      return FALSE;
> >
> >    }
> >
> > -  return (BOOLEAN) (Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
> > (SHF_ALLOC | SHF_WRITE);
> >
> > +  return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
> > (SHF_ALLOC | SHF_WRITE));
> >
> >  }
> >
> >
> >
> >  STATIC
> >
> > diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c
> > b/BaseTools/Source/C/GenFw/Elf64Convert.c
> > index 4ed6b4477e..1bf1e9accb 100644
> > --- a/BaseTools/Source/C/GenFw/Elf64Convert.c
> > +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
> > @@ -270,7 +270,7 @@ IsDataShdr (
> >    if (IsHiiRsrcShdr(Shdr)) {
> >
> >      return FALSE;
> >
> >    }
> >
> > -  return (BOOLEAN) (Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
> > (SHF_ALLOC | SHF_WRITE);
> >
> > +  return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) ==
> > (SHF_ALLOC | SHF_WRITE));
> >
> >  }
> >
> >
> >
> >  STATIC
> >
> > --
> > 2.30.2
> >
> >
> >
> > -=-=-=-=-=-=
> > Groups.io Links: You receive all messages sent to this group.
> > View/Reply Online (#73394): https://edk2.groups.io/g/devel/message/73394
> > Mute This Topic: https://groups.io/mt/81630142/4905953
> > Group Owner: devel+owner@edk2.groups.io
> > Unsubscribe: https://edk2.groups.io/g/devel/unsub
> > [gaoliming@byosoft.com.cn]
> > -=-=-=-=-=-=
> >
>
>
>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#73510): https://edk2.groups.io/g/devel/message/73510
Mute This Topic: https://groups.io/mt/81695559/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-