[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Use a self-defined memory acquirement function instead of realloc(3) in the l_alloc function
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 11 Aug 2020 16:07:25 -0300
> I think it's a solution, but I still have a question.
> >void *newptr = realloc(ptr, nsize);
> > if (newptr == NULL && ptr != NULL && nsize <= osize)
> > return ptr; /* keep the original block */
> If it runs into such code path.
> Which value would you pass to the l_alloc function when invoking it
> next time, nsize or osize(i.e. nsize <= osize)?
> You don't exactly know whether the expression (i.e. newptr == NULL &&
> ptr != NULL && nsize <= osize) is true or not (when this function was
> called last time).
I assume your question is about the 'osize' value . As the contract
says, 'osize' will be the 'nsize' passed in the previous call. Note
that 'osize' is not used by 'realloc', so its value is irrelevant in this
standard implementation of 'l_alloc'.