Common malloc/free practice violates ANSI standard ?

Doug Gwyn gwyn at smoke.BRL.MIL
Fri Oct 20 23:27:50 AEST 1989


In article <646 at targon.UUCP> andre at targon.UUCP (andre) writes:
>The fact that you conclude that the pointer can be changed in value
>when cast from void * to <type> * is wrong, because free() could never
>know what pointer you used and thus howmany bytes back it much go to
>find the pionters of the free list that probably precede your buffer.

This refutation is wrong -- under the (INCORRECT) assumption that
the original malloc()ed pointer has been rounded up by conversion
to an object pointer, free() could still locate the correct chunk
of memory to liberate, under certain reasonable implementation
assumptions.

However, an error in the refutation does not prove the original
claim, which was mistaken all along.



More information about the Comp.lang.c mailing list