nanogui: NULL pointer
Subject:
Re: NULL pointer
From:
"Greg Haerr" ####@####.####
Date:
5 Feb 2001 17:58:12 -0000
Message-Id: <028201c08f99$1c3864c0$15320cd0@gregh>
: void
: GrSendClientData(GR_WINDOW_ID wid, GR_WINDOW_ID did, GR_SERIALNO serial,
: GR_LENGTH len, GR_LENGTH thislen, void *data)
: {
: void *p;
:
: if(!(p = malloc(len))) GsError(GR_ERROR_MALLOC_FAILED, wid);
: memcpy(p, data, thislen);
:
: GsDeliverClientDataEvent(did, wid, serial, len, thislen, p);
: }
Yes, you're right about the return, it should return after the malloc failed...
:
: Actually on second gander this function seems quite messed up.
:
: We are allocating buffer of length "len" then copying into it "thislen"
: bytes. So even if the allocation is happy, the memcpy() could exceed the
: buffer boundary. It looks like the calling function wants a buffer of "len"
: sent back to the client not one of length "thislen".
:
: Another observation, why do we do we allocate a buffer at all. The function
: GsDeliverClientDataEvent() allocates its own buffer and does another
: memcpy() into the new buffer that it creates. It seems that we could save a
: copy by passing the original pointer to the second function.
I included this function, written by Alex, without any testing, as I was trying
to get pre7 out, and I had been sitting on the patch for a month. I think
you're generally correct in your observations. I had asked Alex to test
the get/setselection client test programs, but haven't heard back yet.
The copy is required in the LINK_APP_TO_SERVER case, though.
I am planning on enhancing and generalizing this submission to include
general client-to-client communications, but haven't had a chance yet.
Regards,
Greg