|
From: | Paolo Bonzini |
Subject: | Re: [Qemu-trivial] [Qemu-devel] [PATCH] scripts: add sample model file for Coverity Scan |
Date: | Wed, 19 Mar 2014 17:47:11 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 |
Il 19/03/2014 16:56, Markus Armbruster ha scritto:
> Given the results, okay to > use the limited model where realloc never frees and malloc(0) returns > non-NULL?I'd describe realloc() as "always frees the old block, returns a new block, which is never null". We might mean the same.
Yes, that's what I would do too, but it misses an important difference between malloc() and realloc().
"If size is 0, then malloc() returns either NULL, or a unique pointer value that can later be successfully passed to free()". Instead, for realloc, "if size is equal to zero, and ptr is not NULL, then the call is equivalent to free(ptr)" and presumably must return NULL.
So I'm doubly cheating by giving realloc(foo, 0) free+malloc semantics instead of free.
BTW, this means that the handy "malloc(0) really means malloc(1)" semantics are inconsistent because you cannot implement realloc(foo, 0) that way.
Paolo
Go ahead with the lying^Wlimited model, with a big, fat comment explaining our reasons.
[Prev in Thread] | Current Thread | [Next in Thread] |