• 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:Length: all 00
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSData dataWithBytes:Length: all 00


  • Subject: Re: NSData dataWithBytes:Length: all 00
  • From: "Stephen J. Butler" <email@hidden>
  • Date: Tue, 21 Jul 2009 15:47:44 -0500

On Tue, Jul 21, 2009 at 3:38 PM, Chase Meadors<email@hidden> wrote:
> I have the following code, which is a category on NSData. It is always
> called on especially designated NSData objects with four bytes.
>
> - (NSData *)resolve {
>
>        unsigned char *buf = [self bytes];
>
>        const unsigned char *newBytes[4] = { (buf[3] - 0x08), buf[2], buf[1],
> buf[0] };

When I compile this line, I get all kinds of warnings. Do you? And if
you do, why are you ignoring them? The warning helps point to what is
wrong.

You've allocated an array of four POINTERS, when what you want is an
array of four UNSIGNED CHARACTERS. So it should be:

const unsigned char newBytes[4] = { (buf[3] - 0x08), buf[2], buf[1], buf[0] };


>        for (int i = 0;  i < 4;  i ++) {
>                NSLog(@"X", newBytes[i]);
>        }
>
>        NSData *ret = [NSData dataWithBytes:newBytes length:4];
>        return ret;
>
> }
_______________________________________________

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

References: 
 >NSData dataWithBytes:Length: all 00 (From: Chase Meadors <email@hidden>)

  • Prev by Date: NSData dataWithBytes:Length: all 00
  • Next by Date: Re: NSData dataWithBytes:Length: all 00
  • Previous by thread: NSData dataWithBytes:Length: all 00
  • Next by thread: Re: NSData dataWithBytes:Length: all 00
  • Index(es):
    • Date
    • Thread