Hi Tiran,

Am 11.12.2011 21:57, schrieb Tiran Kaskas:
> Looking into the function alloc_buf_gc() in file buffer.c, it returns a
> struct buffer, which seems to me is allocated on the stack, which is
> causing an issue, I believe, since the function calling alloc_buf_gc()
> will work on a buffer which becomes garbage.

'alloc_buf_gc()' is returning 'buf' (of type 'struct buffer') by value,
not by pointer, so there is no problem here.  If it were returning 'buf'
by pointer your observation would be correct.  (In C++ a typical mistake
would be to return 'buf' by reference.)

The function calling 'alloc_buf_gc()' will copy the contents of 'buf' to
its local instance of 'struct buffer' before continuing.  (An optimised
build might even eliminate the copy.)

Are you observing a specific problem with buffers or did you just happen
to stumble over this piece of code?

Cheers
Fabian

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to