The problem is that you are assuming an oder of evaluation:
testrecv(getbuf(size), size);
// What seems to be happening is
1) size is evaluated and set up for the function call.
2) getbuf() is called. This sets the local copy of size
but the value that is being passed to the function call has already been
evaluated. So this value will not be passed (but the random value that
was in the variable at the time the `size` parameter was evaluated).
3) Function testrecv() called.
Don't rely on side affects.
int size;
void* buf = getbuf(size); // Now size will be set
testrecv(buf, size);