Revision: 304
http://svn.sourceforge.net/substrate/?rev=304&view=rev
Author: landonf
Date: 2006-09-01 23:26:53 -0700 (Fri, 01 Sep 2006)
Log Message:
-----------
Properly initialize the _capacity instance method in NSMutableData's initWithBytesNoCopy:
Modified Paths:
--------------
trunk/Foundation/NSConcreteData.m
Modified: trunk/Foundation/NSConcreteData.m
===================================================================
--- trunk/Foundation/NSConcreteData.m 2006-09-02 05:58:49 UTC (rev 303)
+++ trunk/Foundation/NSConcreteData.m 2006-09-02 06:26:53 UTC (rev 304)
@@ -173,15 +173,24 @@
* @{
*/
+- (id) initWithBytesNoCopy:(void*)bytes length:(unsigned int)length freeWhenDone:(BOOL)freeWhenDone {
+ self = [super initWithBytesNoCopy: bytes length: length freeWhenDone: freeWhenDone];
+ if (!self)
+ return nil;
+
+ _capacity = length;
+ return self;
+}
+
- (id) initWithCapacity:(unsigned int)capacity {
- self = [self init];
+ self = [super init];
if (!self)
return nil;
/* Initialize with 0 length and the specified capacity */
_length = 0;
_capacity = capacity;
- _bytes = malloc(capacity);
+ _bytes = NSZoneMalloc(NULL, capacity);
if (!_bytes) {
[self release];
return nil;
@@ -216,8 +225,12 @@
- (void) _growCapacity:(unsigned int)capacity {
/* Requested length is larger than our capacity.
* We need to realloc. */
- void *new = NSZoneRealloc(NULL, _bytes, capacity);
- _bytes = new;
+ if (_capacity == 0) {
+ _bytes = NSZoneMalloc(NULL, capacity);
+ } else {
+ void *new = NSZoneRealloc(NULL, _bytes, capacity);
+ _bytes = new;
+ }
_capacity = capacity;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|