1

I am getting a strange crash sometimes when getting a string from NSLocalizedStringFromTable. Here is the relevant section of my crash's stacktrace:

CoreFoundation                      0x33c4b7f7 CFEqual   98
CoreFoundation                      0x33cf6a14 __CFBasicHashStandardEquateKeys   20
CoreFoundation                      0x33cf8770 ___CFBasicHashFindBucket_Linear   224
CoreFoundation                      0x33c4b654 CFBasicHashFindBucket   228
CoreFoundation                      0x33c4d4a1 CFDictionaryGetValue   56
CoreFoundation                      0x33c528f5 CFBundleCopyLocalizedString   104
Foundation                          0x32e6ab67 -[NSBundle localizedStringForKey:value:table:]   30
MyApp                          0x000270eb MyApp   155883

The code which causes this is:

NSMutableArray* tableListOptions = [[NSMutableArray alloc] initWithCapacity:1];
[tableListOptions addObject:NSLocalizedStringFromTable(@"My String", @"MyTable", @"")];

Any suggestions as to what might be causing this crash? I use NSLocalizedStringFromTable all the time throughout my app but this location seems to be causing problems, though I am having trouble duplicating the crash consistently.

Jason
  • 14,517
  • 25
  • 92
  • 153
  • You clipped 2 important lines above the stack trace telling the reason for the crash. And before adding the string to the array, can you assign it to a NSString and make a NSLog of it? – ott-- Oct 08 '11 at 23:03
  • Which two lines are you referring to? These are the top lines of the crash report. The report says that it is from a SIGSEGV. The real problem is that it is not reproducible... I have executed the code about 100 times but I haven't been able to reproduce it. However, I have seen numerous crash reports (coming in via BugSense) which point to it, at this exact location and I'm worried that there is something more serious going on. Is it possible for the localization to get corrupted, causing this error? – Jason Oct 08 '11 at 23:17
  • I'd still assign the localized string to a NSString and check it before adding it to the array. – ott-- Oct 08 '11 at 23:59
  • Do you mean in general, that I should assign localized strings to an NSString before adding them to arrays, or just in the debugging situation? – Jason Oct 09 '11 at 00:02
  • I saw that `NSLocalizedStringFromTable()` is just a macro that becomes `[[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:(tbl)]`, so when your key isn't found you're adding @"" to the array. Would that matter? – ott-- Oct 09 '11 at 00:40

0 Answers0