Re: CFDataGetBytes causes crash in socket callback
Re: CFDataGetBytes causes crash in socket callback
- Subject: Re: CFDataGetBytes causes crash in socket callback
- From: Liwei <email@hidden>
- Date: Thu, 2 Oct 2008 02:29:41 +0800
Argh... somehow I was fooled into thinking that it'll do it for me...
Oh well... So I was lucky that it worked in the past :-/
2008/10/2 Frederick Cheung <email@hidden>:
> 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