Re: NSString Question
Re: NSString Question
- Subject: Re: NSString Question
- From: Jason Coco <email@hidden>
- Date: Mon, 18 Aug 2008 13:28:19 -0400
On Aug 18, 2008, at 10:54 , Dave wrote:
Hi,
I'm tring to create an NSString object from data contained within a
file. The following code attempts to do this. The data is read from
the file OK and all the size information etc. is OK.
Here is a code snippet:
myOSStatus = [self ReadUInt32LEFromPosition: myCurrentFilePosition +
28 IntPtr:&myBufferSize];
myStringSize = (myBufferSize / 2) + 1;
myStringBufferPtr = malloc(myBufferSize + 2);
bzero(myStringBufferPtr,myBufferSize + 2);
myOSStatus = [self ReadFromPosition: myCurrentFilePosition + 40
ForSize: myBufferSize BufferPtr:myStringBufferPtr];
[thePropertiesInfoPtr->mNameString initWithCharacters:
myStringBufferPtr length:myStringSize];
---------------------
thePropertiesInfoPtr pointer to a C Structure that contains the
following member:
NSString* mNameString;
When the initWithCharacters method is called, the variables are
setup as follows:
myBufferSize = 54
myStringSize = 28
myStringBufferPtr is a pointer the following:
41 00 42 00 43 00 44 00 45 00 46 00 47 00 48 00
49 00 4A 00 4B 00 4C 00 4D 00 4D 00 4E 00 4F 00
50 00 51 00 52 00 53 00 54 00 55 00 56 00 57 00
58 00 59 00 5A 00 00 00
But I get an Access Error when I run it. Could someone tell me what
I am doing wrong and how I can correct it?
Did you allocate your string first?
[[thePropertiesInfoPtr->mNameString alloc]
initWithCharacters:myStringBufferPtr length:myStringSize];
If you haven't allocated your mNameString variable, chance are it
points to 0x00 and that is why you
are getting an access violation...Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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