[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] loader: don't call realloc(O) when no symbols a
Re: [Qemu-devel] [PATCH] loader: don't call realloc(O) when no symbols are present
Fri, 22 Jan 2010 02:05:40 +0000
Markus Armbruster wrote:
> I didn't claim there's *no* difference between C89 and C99. In fact,
> the Rationale nicely documents the change:
> Also, implementations that support an
> actual allocation when the size is zero do not necessarily return a
> null pointer for this case. C89 appeared to require a null return
> value, and the Committee felt that this was too restrictive.
> So C99 permits realloc(p, 0) to return a non-null value. Regardless, it
> still *requires* it to free(p).
Nobody disagrees that it does free(p).
The question is whether it may _follow_ the free(p) with malloc(0) and
return that, in which case the returned pointer must eventually be
passed to a subsequent free() to avoid leaks, or if it only doess
free(p) and a non-null result must be ignored.
For either meaning of non-null result, there are valid C89 programs which
will break, either leaking or calling free() on an invalid address.
> I just want to correct the misinformation on the standard being
> spread on this list.
I can't tell from your writing which misinformation you mean.
The only thing in question is the (new in C99) possibility of non-null
result and what to do with one (that it does free(p) is not in doubt),
and I'm afriad the sections you quoted firmly support the non-null
result change, and perpetuate the ambiguity of it's meaning.
In any case, there is no doubt, from the possibiliy of non-null result
alone (which is clear), that is already enough to make some valid C89
The ambiguity of a non-null result (i.e. whether it is equivalent to
malloc(0) and the caller must free it later, or it is something the
caller must ignore because the realloc(p,0) call is equivalent to
free(p) only) is what makes it seem unsafe to call realloc(p,0) at all.
I don't want to argue and I really appreciate your clarification if
you know something. If there is misinformation, it would be good to
correct it, in which case I don't think you have succeeded.
Unfortunately I can't tell from your mail what you think the meaning
of a non-null result is.
Re: [Qemu-devel] [PATCH] loader: don't call realloc(O) when no symbols are present, Jamie Lokier, 2010/01/21
Re: [Qemu-devel] [PATCH] loader: don't call realloc(O) when no symbols are present, Markus Armbruster, 2010/01/21
- Re: [Qemu-devel] [PATCH] loader: don't call realloc(O) when no symbols are present, (continued)