Re: Where's the buffer overrun?

2008-03-20 Thread Jean-Daniel Dupas
Le 20 mars 08 à 06:26, Michael Ash a écrit : On Thu, Mar 20, 2008 at 12:56 AM, Jens Alfke [EMAIL PROTECTED] wrote: It's never a good idea to make assumptions about where a Foundation object is putting its data; if you need to access the current bytes of an NSData, call -bytes on it. This

Re: Where's the buffer overrun?

2008-03-20 Thread Michael Ash
On Thu, Mar 20, 2008 at 2:58 AM, Jean-Daniel Dupas [EMAIL PROTECTED] wrote: Le 20 mars 08 à 06:26, Michael Ash a écrit : On Thu, Mar 20, 2008 at 12:56 AM, Jens Alfke [EMAIL PROTECTED] wrote: It's never a good idea to make assumptions about where a Foundation object is putting its

Where's the buffer overrun?

2008-03-19 Thread Nick Zitzmann
I'm probably missing something that's obvious but not so much to me right now... I have an NSArray category method that takes an NSArray of NSString objects, and returns a C array of C strings (char * const *). This is so I can build a C array for some functions that require a C array.

Re: Where's the buffer overrun?

2008-03-19 Thread Chris Suter
On 20/03/2008, at 10:38 AM, Nick Zitzmann wrote: char **returnArray = NSZoneMalloc([self zone], length); should be: char **returnArray = NSZoneMalloc([self zone], length * sizeof (char *)); - Chris ___ Cocoa-dev mailing list

Re: Where's the buffer overrun?

2008-03-19 Thread Andrew Farmer
On 19 Mar 08, at 16:50, Chris Suter wrote: On 20/03/2008, at 10:38 AM, Nick Zitzmann wrote: char **returnArray = NSZoneMalloc([self zone], length); should be: char **returnArray = NSZoneMalloc([self zone], length * sizeof (char *)); Actually, that's correct. Read up a bit -

Re: Where's the buffer overrun?

2008-03-19 Thread Hamish Allan
On Thu, Mar 20, 2008 at 12:00 AM, Andrew Farmer [EMAIL PROTECTED] wrote: What's bothering me a lot more is the use of an appendByte: method. Also bothering me is that a single-byte nul is only correct for certain encodings. Hamish ___ Cocoa-dev

Re: Where's the buffer overrun?

2008-03-19 Thread Chris Suter
On 20/03/2008, at 11:00 AM, Andrew Farmer wrote: On 19 Mar 08, at 16:50, Chris Suter wrote: On 20/03/2008, at 10:38 AM, Nick Zitzmann wrote: char **returnArray = NSZoneMalloc([self zone], length); should be: char **returnArray = NSZoneMalloc([self zone], length * sizeof (char

Re: Where's the buffer overrun?

2008-03-19 Thread Hamish Allan
On Thu, Mar 20, 2008 at 12:18 AM, Chris Suter [EMAIL PROTECTED] wrote: I think it's because [NSMutableData dataWithBytesNoCopy:returnArray length:length] is releasing returnArray and allocating a new buffer for it. I, for one, am surprised that NSMutableData works this way, given that a)

[SOLVED] Re: Where's the buffer overrun?

2008-03-19 Thread Nick Zitzmann
On Mar 19, 2008, at 6:18 PM, Chris Suter wrote: I think it's because [NSMutableData dataWithBytesNoCopy:returnArray length:length] is releasing returnArray and allocating a new buffer for it. I'm guessing that's because it's NSMutableData. To fix it, use NSData instead. Ding ding ding!

Re: Where's the buffer overrun?

2008-03-19 Thread stephen joseph butler
On Wed, Mar 19, 2008 at 7:49 PM, Hamish Allan [EMAIL PROTECTED] wrote: On Thu, Mar 20, 2008 at 12:18 AM, Chris Suter [EMAIL PROTECTED] wrote: I think it's because [NSMutableData dataWithBytesNoCopy:returnArray length:length] is releasing returnArray and allocating a new buffer for

Re: Where's the buffer overrun?

2008-03-19 Thread Nick Zitzmann
On Mar 19, 2008, at 6:49 PM, Hamish Allan wrote: I, for one, am surprised that NSMutableData works this way, given that a) the method name specifically requests that no copy is made, and b) there's no particular reason for it to behave that way unless the data is resized. Thanks again

Re: Where's the buffer overrun?

2008-03-19 Thread Chris Suter
On 20/03/2008, at 12:31 PM, Nick Zitzmann wrote: On Mar 19, 2008, at 6:49 PM, Hamish Allan wrote: I, for one, am surprised that NSMutableData works this way, given that a) the method name specifically requests that no copy is made, and b) there's no particular reason for it to behave that

Re: Where's the buffer overrun?

2008-03-19 Thread Michael Ash
On Thu, Mar 20, 2008 at 12:56 AM, Jens Alfke [EMAIL PROTECTED] wrote: It's never a good idea to make assumptions about where a Foundation object is putting its data; if you need to access the current bytes of an NSData, call -bytes on it. This was a little confusing to me until I thought