[Gc] a bug in v.7.1 ?
bruce at hoult.org
Mon Mar 7 15:38:59 PST 2011
On Tue, Mar 8, 2011 at 8:00 AM, Glauco Masotti <glauco.masotti at libero.it> wrote:
> return v-nl+NR_END;
This is not standards conformant C. POinters to objects must point to
within the object, or 1 item past the end.
It will work fine on pretty much any modern machine and OS, but will
fail hard on one that uses segments and detects out of bounds on them.
Note that even with a traditional malloc(), you can't pass the return
value to free() – you have to pass ptr+nl-NR_END (i.e. v).
You need to make sure that v is stored somewhere that the GC can see
it. Probably the cleanest way is to add an extra argument to vector in
which you pass the address of a local variable which you can
subsequently ignore. This will work unless the array is passed out
from the function that allocates it.
Or, you can rewrite your code to only use arrays where nl is <=
NR_END, as you discovered.
More information about the Gc