Re: __memcpy crash with [NSData -getBytes:range:]

2008-10-10 Thread Clark Cox
On Fri, Oct 10, 2008 at 2:48 AM, Daniel Kennett <[EMAIL PROTECTED]> wrote:
> Hi list,
>
> I'm having trouble reproducing (and fixing) a rare bug that I sometimes get
> reports about.
>
> Here's the code that causes the crash. streamPosition and length are checked
> to make sure they're within the range of the NSData object:
>
> // Allocate a buffer.
> void *buffer = malloc(length);
>
> // Fill the buffer with the requested bytes.
> [_data getBytes:buffer range:NSMakeRange(streamPosition, length)];
>
> Very occasionally, this fails with this crash:
>
> Exception:  EXC_BAD_ACCESS (0x0001)
> Codes:  KERN_PROTECTION_FAILURE (0x0002) at 0x

Since the address above is 0x, I suspect that buffer is NULL.
Are you checking malloc's return value? You may be exceeding your
process' 4GB address space.

-- 
Clark S. Cox III
[EMAIL PROTECTED]
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: __memcpy crash with [NSData -getBytes:range:]

2008-10-10 Thread Matt Gough


On 10 Oct 2008, at 11:48, Daniel Kennett wrote:


// Allocate a buffer.
void *buffer = malloc(length);

// Fill the buffer with the requested bytes.
[_data getBytes:buffer range:NSMakeRange(streamPosition, length)];


Are you sure that buffer has actually been created? Maybe you are  
running out of RAM?


Matt
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


__memcpy crash with [NSData -getBytes:range:]

2008-10-10 Thread Daniel Kennett

Hi list,

I'm having trouble reproducing (and fixing) a rare bug that I  
sometimes get reports about.


Here's the code that causes the crash. streamPosition and length are  
checked to make sure they're within the range of the NSData object:


// Allocate a buffer.
void *buffer = malloc(length);

// Fill the buffer with the requested bytes.
[_data getBytes:buffer range:NSMakeRange(streamPosition, length)];

Very occasionally, this fails with this crash:

Exception:  EXC_BAD_ACCESS (0x0001)
Codes:  KERN_PROTECTION_FAILURE (0x0002) at 0x

Thread 6 Crashed:
0   <<>>0x0d3f __memcpy + 1439 (cpu_capabilities.h:228)
1   com.apple.Foundation	0x9282e456 -[NSConcreteData  
getBytes:range:] + 267


I don't think it's the file that the NSData is created from - indeed,  
the customer sent me a copy of the file in question and it works  
perfectly on my machine. Any help in debugging this would be greatly  
appreciated! Surrounding the code in a @try block doesn't help - it  
still ends up with a hard crash (which is what I was expecting, given  
that is a EXC_BAD_ACCESS).


 Thanks,

-- Daniel

 ___

   [EMAIL PROTECTED]
   http://www.kennettnet.co.uk

Please include previous messages in any reply you send.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]