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