Idiots

Idiots

I added some new RSS feeds to my iPhone application (this is a work project), and when I tried to view one of those feeds, the program died - an uncaught exception - something about accessing an index of an array beyond its bounds. Hmm.

Objective-C is a wonderful language, but when it prints out stack traces using only the 32-bit addresses, it's not as helpful as it might otherwise be. (See picture: oh yes, the problem here is obvious...right.)

Anyway, so, I started digging into writing my own printStackTrace() function based on these addresses, but the best I could do was print the offset of each address within the object file / library. So, at least I could see where my code fell in the stacktrace, but, I knew that already based on the address numbers (tiny numbers = my code, large numbers = system libraries).

So, I finally gave up and loaded the executable into gdb. I fed it the highest address in the stack trace that belonged to my code:

(gdb) x 0xbfce
0xbfce <+[DateThing dateFromString:]+692>: 0x838dc289


Inside dateFromString() I parse a date string and turn it into an NSDate based on its various components. The problem was obvious: the feed I just added used a different date/time format. Wonderful. Same company, different feed, different date format. Of course.

I had previously been working with very nice date formats:

Tue, 12 Aug 2008 14:51:00 EDT

Very easy to parse: the time is in 24-hour (so no AM/PM to deal with), and most of the date components are numeric. The "Tue" can be ignored. All of the components I care about are surrounded by white space (instead of commas). So, an extra if-statement and I've got a print-out the offending date format:

August 15, 2008, 10:30 am

Uggh. Two commas to deal with and I have to set up another month-to-index function. And the time is in stupid 12-hour format. Why?

Back to work.

Subscribe to A garage sale for your mind

Don’t miss out on the latest posts. Sign up now to get access to the library of members-only posts.
[email protected]
Subscribe