• 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: How do I convert data in NSString to NSImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 08:47:32 +0100

On 10/9/03 8:23 am, Ivan Myrvold <email@hidden> wrote:

> Got it working this way:
>
> NSString *picstr; // the string with jpeg data
> NSData *picdata = [NSData dataWithBytes:[picstr cString] length:[picstr
> cStringLength]]; // now picdata contains the jpeg data
> NSImage *myPicture = [[NSImage alloc] initWithData:picdata]; // now we
> have the NSImage

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?

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.

  • Follow-Ups:
    • Re: How do I convert data in NSString to NSImage
      • From: j o a r <email@hidden>
References: 
 >Re: How do I convert data in NSString to NSImage (From: Ivan Myrvold <email@hidden>)

  • Prev by Date: Re: How do I convert data in NSString to NSImage
  • Next by Date: Re: How do I convert data in NSString to NSImage
  • Previous by thread: Re: How do I convert data in NSString to NSImage
  • Next by thread: Re: How do I convert data in NSString to NSImage
  • Index(es):
    • Date
    • Thread