public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH EDK2 v2 0/1] MdeModulePkg/FileExplorerLib: remove redundant null pointer check
@ 2020-11-26  1:50 wenyi,xie
  2020-11-26  1:50 ` [PATCH EDK2 v2 1/1] " wenyi,xie
  0 siblings, 1 reply; 3+ messages in thread
From: wenyi,xie @ 2020-11-26  1:50 UTC (permalink / raw)
  To: devel, jian.j.wang, hao.a.wu, dandan.bi, eric.dong, lersek
  Cc: songdongkuang, xiewenyi2

Main Changes since v1 :
correct commit message.

Wenyi Xie (1):
  MdeModulePkg/FileExplorerLib: remove redundant null pointer check

 MdeModulePkg/Library/FileExplorerLib/FileExplorer.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

-- 
2.20.1.windows.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH EDK2 v2 1/1] MdeModulePkg/FileExplorerLib: remove redundant null pointer check
  2020-11-26  1:50 [PATCH EDK2 v2 0/1] MdeModulePkg/FileExplorerLib: remove redundant null pointer check wenyi,xie
@ 2020-11-26  1:50 ` wenyi,xie
  2020-11-26 12:57   ` Laszlo Ersek
  0 siblings, 1 reply; 3+ messages in thread
From: wenyi,xie @ 2020-11-26  1:50 UTC (permalink / raw)
  To: devel, jian.j.wang, hao.a.wu, dandan.bi, eric.dong, lersek
  Cc: songdongkuang, xiewenyi2

If "Info" is a valid pointer to an EFI_FILE_SYSTEM_VOLUME_LABEL
structure, then "Info->VolumeLabel" denotes a valid array object.
When the "Info->VolumeLabel" expression is evaluated, as seen in
the LibFindFileSystem(), it is implicitly converted to
(&Info->VolumeLabel[0]). Because the object described by the
expression (Info->VolumeLabel[0]) is a valid CHAR16 object, its
address can never compare equal to NULL. Therefore, the condition
(Info->VolumeLabel == NULL) will always evaluate to FALSE.
Substitute the constant FALSE into the "if" statement, and
simplify the resultant code (eliminate the dead branch).

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Signed-off-by: Wenyi Xie <xiewenyi2@huawei.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
---
 MdeModulePkg/Library/FileExplorerLib/FileExplorer.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c
index 58e49102593c..13a214b06af9 100644
--- a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c
+++ b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c
@@ -821,13 +821,9 @@ LibFindFileSystem (
       if (Info == NULL) {
         VolumeLabel = L"NO FILE SYSTEM INFO";
       } else {
-        if (Info->VolumeLabel == NULL) {
-          VolumeLabel = L"NULL VOLUME LABEL";
-        } else {
-          VolumeLabel = Info->VolumeLabel;
-          if (*VolumeLabel == 0x0000) {
-            VolumeLabel = L"NO VOLUME LABEL";
-          }
+        VolumeLabel = Info->VolumeLabel;
+        if (*VolumeLabel == 0x0000) {
+          VolumeLabel = L"NO VOLUME LABEL";
         }
       }
       MenuEntry->DisplayString  = AllocateZeroPool (MAX_CHAR);
-- 
2.20.1.windows.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH EDK2 v2 1/1] MdeModulePkg/FileExplorerLib: remove redundant null pointer check
  2020-11-26  1:50 ` [PATCH EDK2 v2 1/1] " wenyi,xie
@ 2020-11-26 12:57   ` Laszlo Ersek
  0 siblings, 0 replies; 3+ messages in thread
From: Laszlo Ersek @ 2020-11-26 12:57 UTC (permalink / raw)
  To: Wenyi Xie, devel, jian.j.wang, hao.a.wu, dandan.bi, eric.dong
  Cc: songdongkuang

On 11/26/20 02:50, Wenyi Xie wrote:
> If "Info" is a valid pointer to an EFI_FILE_SYSTEM_VOLUME_LABEL
> structure, then "Info->VolumeLabel" denotes a valid array object.
> When the "Info->VolumeLabel" expression is evaluated, as seen in
> the LibFindFileSystem(), it is implicitly converted to
> (&Info->VolumeLabel[0]). Because the object described by the
> expression (Info->VolumeLabel[0]) is a valid CHAR16 object, its
> address can never compare equal to NULL. Therefore, the condition
> (Info->VolumeLabel == NULL) will always evaluate to FALSE.
> Substitute the constant FALSE into the "if" statement, and
> simplify the resultant code (eliminate the dead branch).
> 
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Cc: Dandan Bi <dandan.bi@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Signed-off-by: Wenyi Xie <xiewenyi2@huawei.com>
> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
> ---
>  MdeModulePkg/Library/FileExplorerLib/FileExplorer.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c
> index 58e49102593c..13a214b06af9 100644
> --- a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c
> +++ b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c
> @@ -821,13 +821,9 @@ LibFindFileSystem (
>        if (Info == NULL) {
>          VolumeLabel = L"NO FILE SYSTEM INFO";
>        } else {
> -        if (Info->VolumeLabel == NULL) {
> -          VolumeLabel = L"NULL VOLUME LABEL";
> -        } else {
> -          VolumeLabel = Info->VolumeLabel;
> -          if (*VolumeLabel == 0x0000) {
> -            VolumeLabel = L"NO VOLUME LABEL";
> -          }
> +        VolumeLabel = Info->VolumeLabel;
> +        if (*VolumeLabel == 0x0000) {
> +          VolumeLabel = L"NO VOLUME LABEL";
>          }
>        }
>        MenuEntry->DisplayString  = AllocateZeroPool (MAX_CHAR);
> 

Reviewed-by: Laszlo Ersek <lersek@redhat.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-26 12:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-26  1:50 [PATCH EDK2 v2 0/1] MdeModulePkg/FileExplorerLib: remove redundant null pointer check wenyi,xie
2020-11-26  1:50 ` [PATCH EDK2 v2 1/1] " wenyi,xie
2020-11-26 12:57   ` Laszlo Ersek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox