3

I have written Log helper class which has couple of Log functions. All is working well in DEBUG mode. But when I run my code is release mode it is crashing. Below is the code snippet:

+ (void)info:(NSString *)format, ...
{
    va_list args;
    va_start(args, format);
    va_end(args);

    NSString *formatedMessage = [[NSString alloc] initWithFormat:[NSString stringWithFormat:@"INFO %@",format] arguments:args];
}

While creating formatedMessage app is getting crash with below excecption: Here is the callback of crash

If I set

Build Setting->optimization level to NONE

in Release mode all works smooth. Any idea to fix with Optimization Level to

Fastest-Smallest

in Release mode

Bhumeshwer katre
  • 4,671
  • 2
  • 19
  • 29

1 Answers1

2

You seem to be calling va_end too soon. Try:

+ (void)info:(NSString *)format, ...
{
    va_list args;
    va_start(args, format);

    NSString *formatedMessage = [[NSString alloc] initWithFormat:[NSString stringWithFormat:@"INFO %@",format] arguments:args];

    va_end(args);
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579