diff --git a/NativeScript/runtime/Helpers.h b/NativeScript/runtime/Helpers.h index 7b6cc485..938e4422 100644 --- a/NativeScript/runtime/Helpers.h +++ b/NativeScript/runtime/Helpers.h @@ -240,47 +240,27 @@ static inline void TNS_FormatAndLog(NSString* fmt, ...) { va_list ap; va_start(ap, fmt); - // Convert NSString format to C string and delegate to the main implementation - const char* cFmt = [fmt UTF8String]; - if (!cFmt) { - va_end(ap); + // Use NSString's formatting to handle both C and Objective-C format + // specifiers + NSString* formattedString = + [[NSString alloc] initWithFormat:fmt arguments:ap]; + va_end(ap); + + if (!formattedString) { return; } - // Fast path: try a reasonably sized stack buffer first - const int STACK_BUF_SIZE = 1024; - char stack_buf[STACK_BUF_SIZE]; - - va_list ap_copy; - va_copy(ap_copy, ap); - int needed = vsnprintf(stack_buf, STACK_BUF_SIZE, cFmt, ap_copy); - va_end(ap_copy); - - if (needed < 0) { - va_end(ap); + // Convert to C string for logging + const char* cStr = [formattedString UTF8String]; + if (!cStr) { return; } - if (needed < STACK_BUF_SIZE) { - // Message fit into stack buffer -#if TNS_HAVE_OS_LOG - os_log(OS_LOG_DEFAULT, "%{public}s", stack_buf); -#else - NSLog(@"%s", stack_buf); -#endif - } else { - // Needs heap allocation - std::vector buffer((size_t)needed + 1); - vsnprintf(buffer.data(), buffer.size(), cFmt, ap); - #if TNS_HAVE_OS_LOG - os_log(OS_LOG_DEFAULT, "%{public}s", buffer.data()); + os_log(OS_LOG_DEFAULT, "%{public}s", cStr); #else - NSLog(@"%s", buffer.data()); + NSLog(@"%s", cStr); #endif - } - - va_end(ap); } #endif @@ -337,7 +317,7 @@ static inline void TNS_FormatAndLog(const char* fmt, ...) { } // Keep the existing Log(...) macro name for call-site compatibility. -#define Log(...) TNS_FormatAndLog(__VA_ARGS__) +#define Log(...) tns::TNS_FormatAndLog(__VA_ARGS__) v8::Local JsonStringifyObject(v8::Local context, v8::Local value,