public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "JoeX Lu" <pen-chunx.lu@intel.com>
To: devel@edk2.groups.io
Cc: JoeX Lu <pen-chunx.lu@intel.com>,
	Jian J Wang <jian.j.wang@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>,
	Dandan Bi <dandan.bi@intel.com>, Eric Dong <eric.dong@intel.com>,
	Jiewen Yao <jiewen.yao@intel.com>
Subject: [PATCH] Fix GCC5 Release build warning [-Wreturn-local-addr]
Date: Tue, 25 Apr 2023 14:40:27 +0800	[thread overview]
Message-ID: <20230425064027.18117-1-pen-chunx.lu@intel.com> (raw)

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: devel@edk2.groups.io
Cc: Jiewen Yao <jiewen.yao@intel.com>
Signed-off-by: JoeX Lu <pen-chunx.lu@intel.com>
---
 MdeModulePkg/Library/UefiHiiLib/HiiLib.c      | 20 ++++++++++++-------
 .../HashLibBaseCryptoRouterPei.c              | 19 ++++++++++++++----
 2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
index 63a37ab59a..a024d3b8d2 100644
--- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
+++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
@@ -3415,25 +3415,31 @@ HiiCreateGuidOpCode (
   IN UINTN           OpCodeSize
   )
 {
-  EFI_IFR_GUID  OpCode;
+  EFI_IFR_GUID  *OpCode;
   EFI_IFR_GUID  *OpCodePointer;
 
   ASSERT (Guid != NULL);
   ASSERT (OpCodeSize >= sizeof (OpCode));
 
-  ZeroMem (&OpCode, sizeof (OpCode));
-  CopyGuid ((EFI_GUID *)(VOID *)&OpCode.Guid, Guid);
+  OpCode = (EFI_IFR_GUID *) AllocateZeroPool (sizeof (EFI_IFR_GUID));
+  if (OpCode == NULL) {
+    return NULL;
+  }
+  CopyGuid ((EFI_GUID *)(VOID *)&OpCode->Guid, Guid);
 
   OpCodePointer = (EFI_IFR_GUID *)InternalHiiCreateOpCodeExtended (
                                     OpCodeHandle,
-                                    &OpCode,
+                                    OpCode,
                                     EFI_IFR_GUID_OP,
-                                    sizeof (OpCode),
-                                    OpCodeSize - sizeof (OpCode),
+                                    sizeof (EFI_IFR_GUID),
+                                    OpCodeSize - sizeof (EFI_IFR_GUID),
                                     0
                                     );
   if ((OpCodePointer != NULL) && (GuidOpCode != NULL)) {
-    CopyMem (OpCodePointer + 1, (EFI_IFR_GUID *)GuidOpCode + 1, OpCodeSize - sizeof (OpCode));
+    CopyMem (OpCodePointer + 1, (EFI_IFR_GUID *)GuidOpCode + 1, OpCodeSize - sizeof (EFI_IFR_GUID));
+  }
+  if (OpCode != NULL) {
+    FreePool (OpCode);
   }
 
   return (UINT8 *)OpCodePointer;
diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c
index eeb424b6c3..c8052fed15 100644
--- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c
+++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c
@@ -84,11 +84,22 @@ InternalCreateHashInterfaceHob (
   EFI_GUID  *Identifier
   )
 {
-  HASH_INTERFACE_HOB  LocalHashInterfaceHob;
+  HASH_INTERFACE_HOB  *LocalHashInterfaceHob;
+  HASH_INTERFACE_HOB  *HobBuffer;
 
-  ZeroMem (&LocalHashInterfaceHob, sizeof (LocalHashInterfaceHob));
-  CopyGuid (&LocalHashInterfaceHob.Identifier, Identifier);
-  return BuildGuidDataHob (&mHashLibPeiRouterGuid, &LocalHashInterfaceHob, sizeof (LocalHashInterfaceHob));
+  HobBuffer = NULL;
+  LocalHashInterfaceHob = AllocateZeroPool (sizeof (HASH_INTERFACE_HOB));
+  if (LocalHashInterfaceHob == NULL) {
+    return NULL;
+  }
+
+  CopyGuid (&LocalHashInterfaceHob->Identifier, Identifier);
+  HobBuffer = (HASH_INTERFACE_HOB *) BuildGuidDataHob (&mHashLibPeiRouterGuid, &LocalHashInterfaceHob, sizeof (LocalHashInterfaceHob));
+
+  if (LocalHashInterfaceHob != NULL) {
+    FreePool (LocalHashInterfaceHob);
+  }
+  return HobBuffer;
 }
 
 /**
-- 
2.31.1.windows.1


             reply	other threads:[~2023-04-25  6:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-25  6:40 JoeX Lu [this message]
2023-04-27  2:25 ` 回复: [edk2-devel] [PATCH] Fix GCC5 Release build warning [-Wreturn-local-addr] gaoliming
2023-04-27  2:32   ` JoeX Lu
2023-04-27  2:46   ` JoeX Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230425064027.18117-1-pen-chunx.lu@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox