util/wrapper.c: Fix gcc warning in xrealloc()
Vishal Verma
maintainerPATCH 1/1 util/wrapper.c: Fix gcc warning in xrealloc()
A GCC update (12.1.1) now produces a warning in the xrealloc() wrapper (originally copied from git, and used in strbuf operations):
../util/wrapper.c: In function ‘xrealloc’:
../util/wrapper.c:34:31: warning: pointer ‘ptr’ may be used after ‘realloc’ [-Wuse-after-free]
34 | ret = realloc(ptr, 1);
| ^~~~~~~~~~~~~~~Pull in an updated definition for xrealloc() from the git project to fix this.
--- util/wrapper.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
util/wrapper.c +9 -9
@@ -25,15 +25,15 @@ char *xstrdup(const char *str)void *xrealloc (void *ptr,size_t size) { -void *ret =realloc (ptr, size); -if (!ret && !size) - ret =realloc (ptr,1 ); -if (!ret) { - ret =realloc (ptr, size); -if (!ret && !size) - ret =realloc (ptr,1 ); -if (!ret) -die ("Out of memory, realloc failed" ); +void *ret; + +if (!size) { +free (ptr); +return malloc (1 ); } + + ret =realloc (ptr, size); +if (!ret) +die ("Out of memory, realloc failed" );return ret; }
base-commit: 3e17210345482ec9795f1046c766564d3b8a0795
Signature · 1 line
2.36.1
Quoted 5 lines · Vishal Verma
A GCC update (12.1.1) now produces a warning in the
xrealloc()wrapper (originally copied from git, and used in strbuf operations):
../util/wrapper.c: In function ‘xrealloc’:
../util/wrapper.c:34:31: warning: pointer ‘ptr’ may be used after ‘realloc’ [-Wuse-after-free]
Quoted 7 lines
34 | ret = realloc(ptr, 1); | ^~~~~~~~~~~~~~~Pull in an updated definition for
xrealloc()from the git project to fix this.Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Looks like a faithful reproduction of what upstream git did minus the memory_limit_check() infra, but we can think about that later.
Verma, Vishal L
maintainerQuoted 11 lines · Dan Williams
Quoted 10 lines · Vishal Verma
A GCC update (12.1.1) now produces a warning in the
xrealloc()wrapper
(originally copied from git, and used in strbuf operations):
../util/wrapper.c: In function ‘xrealloc’:
../util/wrapper.c:34:31: warning: pointer ‘ptr’ may be used after ‘realloc’ [-Wuse-after-free]
34 | ret =realloc(ptr, 1); | ^~~~~~~~~~~~~~~
Quoted 8 lines
Quoted 5 lines
Pull in an updated definition for
xrealloc()from the git project to fix this.Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>Looks like a faithful reproduction of what upstream git did minus the
memory_limit_check()infra, but we can think about that later.
And minus the xmalloc() stuff, but I don't think we /need/ that (yet).
Quoted 2 lines
Reviewed-by Dan Williams <[email protected]>
Thanks!