Blame SOURCES/0173-util-wrapper.c-Fix-gcc-warning-in-xrealloc.patch

e0018b
From bbb2cb56f08d95ecf2c7c047a33cc3dd64eb7fde Mon Sep 17 00:00:00 2001
e0018b
From: Vishal Verma <vishal.l.verma@intel.com>
e0018b
Date: Thu, 16 Jun 2022 13:35:29 -0600
e0018b
Subject: [PATCH 173/217] util/wrapper.c: Fix gcc warning in xrealloc()
e0018b
MIME-Version: 1.0
e0018b
Content-Type: text/plain; charset=UTF-8
e0018b
Content-Transfer-Encoding: 8bit
e0018b
e0018b
A GCC update (12.1.1) now produces a warning in the xrealloc() wrapper
e0018b
(originally copied from git, and used in strbuf operations):
e0018b
e0018b
  ../util/wrapper.c: In function ‘xrealloc’:
e0018b
  ../util/wrapper.c:34:31: warning: pointer ‘ptr’ may be used after ‘realloc’ [-Wuse-after-free]
e0018b
     34 |                         ret = realloc(ptr, 1);
e0018b
        |                               ^~~~~~~~~~~~~~~
e0018b
e0018b
Pull in an updated definition for xrealloc() from the git project to fix this.
e0018b
e0018b
Link: https://lore.kernel.org/r/20220616193529.56513-1-vishal.l.verma@intel.com
e0018b
Cc: Dan Williams <dan.j.williams@intel.com>
e0018b
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
e0018b
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
e0018b
---
e0018b
 util/wrapper.c | 18 +++++++++---------
e0018b
 1 file changed, 9 insertions(+), 9 deletions(-)
e0018b
e0018b
diff --git a/util/wrapper.c b/util/wrapper.c
e0018b
index 026a54f..6adfde6 100644
e0018b
--- a/util/wrapper.c
e0018b
+++ b/util/wrapper.c
e0018b
@@ -25,15 +25,15 @@ char *xstrdup(const char *str)
e0018b
 
e0018b
 void *xrealloc(void *ptr, size_t size)
e0018b
 {
e0018b
-	void *ret = realloc(ptr, size);
e0018b
-	if (!ret && !size)
e0018b
-		ret = realloc(ptr, 1);
e0018b
-	if (!ret) {
e0018b
-		ret = realloc(ptr, size);
e0018b
-		if (!ret && !size)
e0018b
-			ret = realloc(ptr, 1);
e0018b
-		if (!ret)
e0018b
-			die("Out of memory, realloc failed");
e0018b
+	void *ret;
e0018b
+
e0018b
+	if (!size) {
e0018b
+		free(ptr);
e0018b
+		return malloc(1);
e0018b
 	}
e0018b
+
e0018b
+	ret = realloc(ptr, size);
e0018b
+	if (!ret)
e0018b
+		die("Out of memory, realloc failed");
e0018b
 	return ret;
e0018b
 }
e0018b
-- 
e0018b
2.27.0
e0018b