On Aug 23, 2008, at 11:44 AM, Kyle Sluder wrote:
On Sat, Aug 23, 2008 at 2:09 PM, Roland Silver <[EMAIL PROTECTED]> wrote:
Is there a convenience function (or method) foo() with int arg and NSString*
value for converting an error code to a string?

This program:
#include <stdio.h>

int main(int argc, char **argv)
{
       int a = 560227702;
       char *b = (char*)(&a);
       printf("%c%c%c%c%c", b[0], b[1], b[2], b[3], b[4]);
       return 0;
}

Produces this output:
$ ./a.out
ved!?

It's close... dunno what magic is going on, but it shouldn't be that
hard to do yourself.  What bothers me is that you have a five
character error code ("!idev") whereas an int is only 4 bytes wide.  I
wrote my code with 5 characters, but it's an obvious out-of-bounds
access.

Huh? There is no reason why accessing b[4] should crash. Produce a random value? Sure, but not crash. You are just accessing one byte past a stack based array and, thus, reading a random byte off the stack.

If you want to crash, try:

((char *)0x1) = 'a';

Or the like.

Is there a convenience function (or method) foo() with int arg and NSString* value for converting an error code to a string?
For example, given error code errcode = 560227702 = 0x21646576,
foo(errcode) = @"!idev"?

Actually, I'm not even sure what the OP is asking for. Where did the error code come from and why do you think converting it to the string '!idev' is going to be useful?

Ahh... it is kAudioHardwareBadDeviceError from Core Audio. That is, there is a constant defined and you can do comparisons to see which error you have. Converting to the four+ character gobbledy-gook really isn't going to help much. A quick search reveals this bit of code which might be quite helpful:

http://www.martux.org/qemu_old/qemu-0.8.2-solaris__20061010x11/audio/coreaudio.c

b.bum

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to