Re: NSData dataWithBytes:Length: all 00

2009-07-21 Thread James Walker

Chase Meadors 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] };



You've declared an array of pointers to bytes, not an array of bytes. 
Take out that asterisk.




for (int i = 0;  i < 4;  i ++) {

NSLog(@"%02X", newBytes[i]);
}

NSData *ret = [NSData dataWithBytes:newBytes length:4];

return ret;

}


The for statement logging the individual bytes is exactly as expected. 
However, the new data object ret is <>. I couldn't really find 
an answer on google, probably because it's a simple answer I'm missing, 
so I asked here. Thanks for any help.

___




--
  James W. Walker, Innoventive Software LLC
  
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSData dataWithBytes:Length: all 00

2009-07-21 Thread Stephen J. Butler
On Tue, Jul 21, 2009 at 3:38 PM, Chase Meadors 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(@"%02X", newBytes[i]);
>        }
>
>        NSData *ret = [NSData dataWithBytes:newBytes length:4];
>        return ret;
>
> }
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSData dataWithBytes:Length: all 00

2009-07-21 Thread Chase Meadors
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] };


for (int i = 0;  i < 4;  i ++) {
NSLog(@"%02X", newBytes[i]);
}

NSData *ret = [NSData dataWithBytes:newBytes length:4];
return ret;

}

The for statement logging the individual bytes is exactly as expected.  
However, the new data object ret is <>. I couldn't really find  
an answer on google, probably because it's a simple answer I'm  
missing, so I asked here. Thanks for any help.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com