From: Andreas Schwab Date: Tue, 01 Sep 2020 15:20:23 GMT Subject: Re: [PATCH] xrealloc: do not reuse pointer freed by zero-length realloc() Message-ID: <87o8mp8qx4.fsf@igel.home> In-Reply-To: <20200901111800.GA3115584@coredump.intra.peff.net> On Sep 01 2020, Jeff King wrote: > diff --git a/wrapper.c b/wrapper.c > index 4ff4a9c3db..b0d375beee 100644 > --- a/wrapper.c > +++ b/wrapper.c > @@ -120,7 +120,7 @@ void *xrealloc(void *ptr, size_t size) > memory_limit_check(size, 0); > ret = realloc(ptr, size); > if (!ret && !size) > - ret = realloc(ptr, 1); > + ret = realloc(ret, 1); Since you already know ret == NULL, you could just say malloc(1), As written, it looks like a typo (why use a variable to pass a constant?). Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."