Re: A CFStringRef that throws EXC_BAD_ACCESS
Re: A CFStringRef that throws EXC_BAD_ACCESS
- Subject: Re: A CFStringRef that throws EXC_BAD_ACCESS
- From: Rosyna <email@hidden>
- Date: Thu, 17 Oct 2002 04:53:05 -0700
Ack, at 10/17/02, Craig Bakalian said:
>
CFStringRef pmaxtrans;
>
MIDIDeviceRef dev;
>
>
MIDIObjectGetStringProperty(dev, kMIDIPropertyMaxTransmitChannels,
>
&pmaxtrans); put ref in pmaxtrans
>
CFStringGetCString(pmaxtrans, cmaxtrans, sizeof(pmaxtrans), 0);
>
//set the stringRef to a string
>
[self setMaxTransChannels: [NSString stringWithCString:
>
cmaxtrans]]; //put string in NSString
I don't see why you are doing this. You could just as easily do [self
setMaxTransChannels:(NSString*)pmaxtrans]; and get rid of the
CFGetCString all together. And there is an extremely good chance that
cmaxtrans isn't big enough to hold the decomposed UTF-8 string. And
in the code below:
>
The CFStringGetCString threw the bad access error because I was not
>
checking the return value of the MIDIObjectGetStringProperty(blah,
>
blah,blah). So, I did this
>
>
>
CFStringRef pmaxtrans;
>
MIDIDeviceRef dev;
>
>
OSStatus TransErr = MIDIObjectGetStringProperty(dev,
>
kMIDIPropertyMaxTransmitChannels, &pmaxtrans);
>
if(TransErr != kMIDIUnknownProperty ){
>
CFStringGetCString(pmaxtrans, cmaxtrans, sizeof(pmaxtrans), 0);
>
CFRelease(pmaxtrans);
>
[self setMaxTransChannels: [NSString stringWithCString: cmaxtrans]];
I am guessing this never gets called as it seems like it would crash
immediately. First, you are using CFRelease to release something that
you shouldn't (the function you got it from doesn't contain the words
Copy or Create) which should crash. Second, you get the C string from
the CFString but release the CFString before using the C string which
should also probably crash.
>
}
--
Sincerely,
Rosyna Keller
Technical Support/Holy Knight/Always needs a hug
Unsanity: Unsane Tools for Insanely Great People
---
Please include any previous correspondence in replies, it helps me
remember what we were talking about. Thanks.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.