• 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: NSData dataWithBytes problem on Intel
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSData dataWithBytes problem on Intel


  • Subject: Re: NSData dataWithBytes problem on Intel
  • From: Andy Lee <email@hidden>
  • Date: Wed, 21 Mar 2007 14:57:40 -0400

Now that was a sneaky bug!

The other lessons are:
 * Beware of functions/methods with side effects.
 * Don't assume evaluation order of arguments to functions/methods.
 * Use global variables judiciously.

--Andy

On Mar 21, 2007, at 2:27 PM, Sam Waters wrote:

The solution:

Here's what I was doing:

NSData * dTempData = [NSData dataWithBytes:[self Function] length:iLen];

iLen is a class variable that got updated in Function. On the PPC iLen would be
updated in time, but on the Intel it wouldn't be. Oddly enough that same line
of code works fine on my Windows XP port. (in C++ syntax of course)


The moral of the story is KEEP YOUR CONSOLE OPEN. When it tells you you're
trying to create an NSData object with an "absurd" length, bugs like this are
much easier to find!



--- Sam Waters <email@hidden> wrote:

OK, I'll look more closely to see if I'm stomping on memory I shouldn't be.
It
seems I'm not misusing NSData which is what I was most worried about. I must
be
overwriting something important for dTempData somehow.


Thanks for the help.
--- Scott Stevenson <email@hidden> wrote:


On Mar 20, 2007, at 6:04 PM, Sam Waters wrote:

I've found that if I do this:

NSData * dTempData = [NSData dataWithBytes:pBytes length:iLen];

and later on do this:

NSData * dTempData2 = [NSData dataWithBytes:pOtherBytes
length:iOtherLen];

then everything is fine for both Intel and PPC, but am worried I'm
doing
something fundamentally wrong. PLEASE let me know if I'm doing
something
terribly wrong here, I'm new at this!

I think the bug is probably outside of the code you're showing us because there's no way for NSData to know which variable you're assigning object pointer to.

Try something like this:

NSData * dTempData = [NSData dataWithBytes:pBytes length:iLen];
pOtherBytes = pBytes;
iOtherLen = iLen;
dTempData = [NSData dataWithBytes:pOtherBytes length:iOtherLen];

If that works, then it's probably a problem with the way either
pOtherBytes or iOtherLen is being set up. On the other hand, if it
still crashes, then it might have something to do with the way
dTempData is being used after the second assignment.

As for why you see problems on Intel and not PowerPC, it's hard to
say without knowing seeing the context of the rest of the code.

     - Scott
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
40yahoo.com


This email sent to email@hidden






______________________________________________________________________ ______________
Food fight? Enjoy some healthy debate
in the Yahoo! Answers Food & Drink Q&A.
http://answers.yahoo.com/dir/?link=list&sid=396545367
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
40yahoo.com


This email sent to email@hidden





______________________________________________________________________ ______________
Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/
_______________________________________________


Cocoa-dev mailing list (email@hidden)

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

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


References: 
 >Re: NSData dataWithBytes problem on Intel (From: Sam Waters <email@hidden>)

  • Prev by Date: Re: Glyph from Character
  • Next by Date: Why does (id <MyProtocol>) have to be id?
  • Previous by thread: Re: NSData dataWithBytes problem on Intel
  • Next by thread: Re: NSData dataWithBytes problem on Intel
  • Index(es):
    • Date
    • Thread