You are right, I somehow mixed the data ptr with the struct copy by value.
I do have a problem with returning structures with my 16 bit machine, seems 
some of the data not being copied (probably need to define far segment).

-----Original Message-----
From: Fabian Knittel [mailto:fabian.knit...@avona.com] 
Sent: Monday, December 12, 2011 12:11 AM
To: Tiran Kaskas
Cc: openvpn-devel@lists.sourceforge.net
Subject: Re: [Openvpn-devel] Problem with alloc_buf_gc function

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

Reply via email to