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

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