diff mbox

[edk2,3/4] CryptoPkg: RuntimeCryptLib: support realloc(NULL, size)

Message ID 1456348432-18818-4-git-send-email-lersek@redhat.com
State Accepted
Commit e89d672110aaf1c5a85404375ca6767b099d3b50
Headers show

Commit Message

Laszlo Ersek Feb. 24, 2016, 9:13 p.m. UTC
The ISO C standard says about realloc(),

  If ptr is a null pointer, the realloc function behaves like the malloc
  function for the specified size.

The realloc() implementation doesn't conform to this currently, so add a
check and call malloc() if appropriate.

Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Qin Long <qin.long@intel.com>
Cc: Ting Ye <ting.ye@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>

---
 CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c | 4 ++++
 1 file changed, 4 insertions(+)

-- 
1.8.3.1


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

Patch

diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c b/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c
index 45ef9ff5f252..413e47e92325 100644
--- a/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c
+++ b/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c
@@ -396,6 +396,10 @@  void *realloc (void *ptr, size_t size)
   UINTN  StartPageIndex;
   UINTN  PageCount;
 
+  if (ptr == NULL) {
+    return malloc (size);
+  }
+
   //
   // Get Original Size of ptr
   //