• 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: error codes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: error codes


  • Subject: Re: error codes
  • From: Bill Bumgarner <email@hidden>
  • Date: Sat, 23 Aug 2008 11:54:07 -0700

On Aug 23, 2008, at 11:44 AM, Kyle Sluder wrote:
On Sat, Aug 23, 2008 at 2:09 PM, Roland Silver <email@hidden> 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 (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

  • Follow-Ups:
    • Re: error codes
      • From: "Kyle Sluder" <email@hidden>
References: 
 >error codes (From: Roland Silver <email@hidden>)
 >Re: error codes (From: "Kyle Sluder" <email@hidden>)

  • Prev by Date: Re: error codes
  • Next by Date: Re: Implementing isEqual: and hash
  • Previous by thread: Re: error codes
  • Next by thread: Re: error codes
  • Index(es):
    • Date
    • Thread