Crash in release mode when generating NSString with arguments

I wrote a log helper class that has a couple of log functions. Everything works well in DEBUG mode. But when I run my code it is release mode it crashes. 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];
}

      

The formatedMessage fails when using the below: Here is the failure callback

If I installed

Build setting-> optimization level to NONE

in release mode, everything runs smoothly. Any idea to fix it with an optimization level

fastest smallest

in release mode

+3


source to share


1 answer


You seem to be calling too quickly va_end

. 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);
}

      

+1


source







All Articles