Re: CFDataGetBytes causes crash in socket callback
Re: CFDataGetBytes causes crash in socket callback
- Subject: Re: CFDataGetBytes causes crash in socket callback
- From: Frederick Cheung <email@hidden>
- Date: Wed, 1 Oct 2008 18:51:20 +0100
CFDataGetBytes is expecting you to pass it a pointer to a buffer of
sufficient size, but you are passing it an uninitialized pointer
(databuf)
Fred
Sent from my iPhone
On 1 Oct 2008, at 18:36, Liwei <email@hidden> wrote:
I have setup a socket for UDP using CFSocket and bound it to
localhost.
However every time data is received it crashes when I try to copy out
the data for printing. The relevant callback function is this:
void receiveData(CFSocketRef socket, CFSocketCallBackType type,
CFDataRef address, const void *data, void *info){
UInt8 *databuf;
CFMutableDataRef localdata =
CFDataCreateMutableCopy(kCFAllocatorDefault, 0, data);
if(localdata != NULL){
CFDataAppendBytes(localdata, (UInt8 *)"", 1);
CFDataGetBytes(localdata,CFRangeMake(0,
CFDataGetLength(localdata)), databuf);
printf("%s", databuf);
}
return;
}
It crashes at CFDataGetBytes with a EXEC_BAD_ACCESS
I think it worked in the past (its been some time since I fiddled with
this code) before I shuffled some stuff around. Anyone knows what the
problem might be?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden