• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Where's the buffer overrun?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Where's the buffer overrun?


  • Subject: Re: Where's the buffer overrun?
  • From: "Hamish Allan" <email@hidden>
  • Date: Thu, 20 Mar 2008 00:49:28 +0000

On Thu, Mar 20, 2008 at 12:18 AM, Chris Suter
<email@hidden> 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) 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. However, the following test code confirms it:

#import <Cocoa/Cocoa.h>

int main()
{
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
	char *test_string = malloc(8);
	strncpy(test_string, "testing", 8);
	NSData *data = [NSData dataWithBytesNoCopy:test_string length:8];
	NSMutableData *mutableData = [NSMutableData
dataWithBytesNoCopy:test_string length:8];
	NSLog(@"%p", test_string);
	NSLog(@"%p", [data bytes]);
	NSLog(@"%p", [mutableData bytes]);
	[pool release];
	return 0;
}

$ gcc -framework Cocoa test_string.m
$ ./a.out
2008-03-20 00:42:24.924 a.out[1657:10b] 0x1091d0
2008-03-20 00:42:24.926 a.out[1657:10b] 0x1091d0
2008-03-20 00:42:24.927 a.out[1657:10b] 0x109cb0
$

Hamish
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Where's the buffer overrun?
      • From: Jens Alfke <email@hidden>
    • Re: Where's the buffer overrun?
      • From: Nick Zitzmann <email@hidden>
    • Re: Where's the buffer overrun?
      • From: "stephen joseph butler" <email@hidden>
References: 
 >Where's the buffer overrun? (From: Nick Zitzmann <email@hidden>)
 >Re: Where's the buffer overrun? (From: Chris Suter <email@hidden>)
 >Re: Where's the buffer overrun? (From: Andrew Farmer <email@hidden>)
 >Re: Where's the buffer overrun? (From: Chris Suter <email@hidden>)

  • Prev by Date: Synchronous Ruby calls from Safari?
  • Next by Date: __setjmp linking error in Leopard
  • Previous by thread: Re: Where's the buffer overrun?
  • Next by thread: Re: Where's the buffer overrun?
  • Index(es):
    • Date
    • Thread