Fix bad access to null variadic args

This removes the need to access `va_list` in a non-variadic function.

By adding a variadic logging function, we can still bridge `RCTLogFunction`, without changing the public API of `IBGNSLogWithLevel` to not require a `va_list`.

This also removes the need to call the log function on the main queue, which was applied in #76 (7cc7e90a5a49629519706942334c9e6e9957e628).

Fixes #82
This commit is contained in:
Eli Perkins 2017-10-09 15:28:10 -04:00 committed by GitHub
parent 58ce2587ef
commit 741afec07b

View File

@ -442,6 +442,15 @@ RCT_EXPORT_METHOD(isRunningLive:(RCTResponseSenderBlock)callback) {
return [iOSVersion compare:[UIDevice currentDevice].systemVersion options:NSNumericSearch] == NSOrderedDescending; return [iOSVersion compare:[UIDevice currentDevice].systemVersion options:NSNumericSearch] == NSOrderedDescending;
}; };
// Note: This function is used to bridge IBGNSLog with RCTLogFunction.
// This log function should not be used externally and is only an implementation detail.
void RNIBGLog(IBGLogLevel logLevel, NSString *format, ...) {
va_list arg_list;
va_start(arg_list, format);
IBGNSLogWithLevel(format, arg_list, logLevel);
va_end(arg_list);
}
RCTLogFunction InstabugReactLogFunction = ^( RCTLogFunction InstabugReactLogFunction = ^(
RCTLogLevel level, RCTLogLevel level,
__unused RCTLogSource source, __unused RCTLogSource source,
@ -450,30 +459,27 @@ RCTLogFunction InstabugReactLogFunction = ^(
NSString *message NSString *message
) )
{ {
NSString *formatString = @"Instabug - REACT LOG: %@";
NSString *log = RCTFormatLog([NSDate date], level, fileName, lineNumber, message); NSString *log = RCTFormatLog([NSDate date], level, fileName, lineNumber, message);
NSString *compeleteLog = [NSString stringWithFormat:@"Instabug - REACT LOG: %@", log];
dispatch_async(dispatch_get_main_queue(), ^{
va_list arg_list;
switch(level) { switch(level) {
case RCTLogLevelTrace: case RCTLogLevelTrace:
IBGNSLogWithLevel(compeleteLog, arg_list, IBGLogLevelTrace); RNIBGLog(IBGLogLevelTrace, formatString, log);
break; break;
case RCTLogLevelInfo: case RCTLogLevelInfo:
IBGNSLogWithLevel(compeleteLog, arg_list, IBGLogLevelInfo); RNIBGLog(IBGLogLevelInfo, formatString, log);
break; break;
case RCTLogLevelWarning: case RCTLogLevelWarning:
IBGNSLogWithLevel(compeleteLog, arg_list, IBGLogLevelWarning); RNIBGLog(IBGLogLevelWarning, formatString, log);
break; break;
case RCTLogLevelError: case RCTLogLevelError:
IBGNSLogWithLevel(compeleteLog, arg_list, IBGLogLevelError); RNIBGLog(IBGLogLevelError, formatString, log);
break; break;
case RCTLogLevelFatal: case RCTLogLevelFatal:
IBGNSLogWithLevel(compeleteLog, arg_list, IBGLogLevelFatal); RNIBGLog(IBGLogLevelFatal, formatString, log);
break; break;
} }
});
}; };
@end @end