Re: How do I convert data in NSString to NSImage
Re: How do I convert data in NSString to NSImage
- Subject: Re: How do I convert data in NSString to NSImage
- From: Chris Ridd <email@hidden>
- Date: Wed, 10 Sep 2003 11:31:01 +0100
On 10/9/03 9:11 am, j o a r <email@hidden> wrote:
>
>
On onsdag, september 10, 2003, at 09:47 AM, Chris Ridd wrote:
>
>
> That's only going to work by luck, isn't it?
>
> Since any JPEG is quite likely to have a NUL byte somewhere inside it,
>
> [picstr cStringLength] is going to return a "too short" value. The
>
> value
>
> you're passing for length probably doesn't really matter, but if NSData
>
> starts to copy stuff around, you're going to lose.
>
> Conversely, if the JPEG *doesn't* have a NUL byte inside it, [picstr
>
> cStringLength] is going to walk off reading unallocated memory and
>
> possibly
>
> crash your app :-(
>
> How exactly did you read the JPEG into an NSString in the first place?
>
> Is it
>
> possible to read it into a more appropriate data structure?
>
>
You could use a string, but you'd have to make sure that you encode it
>
properly to avoid problems like this. I have a category on NSData that
>
I use for a similar purpose (I think it's applicable here, let me know
>
if I'm wrong). Using these methods it should be easy to go from data -
>
string and then back to data on the other end.
>
>
@implementation NSData (HexStringRepresentations)
Well yes, you can store arbitrary stuff in a string if you encode it in hex
or base 47 or something, but that's pretty gross :-)
I've got plenty of code here that uses that technique for historical reasons
:-((
Cheers,
Chris
_______________________________________________
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.