From 145b923293b025fab41fb13ebde575031664370c Mon Sep 17 00:00:00 2001 From: Hamish Knight Date: Wed, 17 Jul 2024 21:25:54 +0100 Subject: [PATCH] Ensure macOS logging uses UTF-8 Previously we were using `NSLog`'s `%s` specifier, but that uses the default system encoding instead of UTF-8. Convert to NSString to ensure we can handle UTF-8 log messages. rdar://131747774 --- lib/Support/Logging-Mac.mm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Support/Logging-Mac.mm b/lib/Support/Logging-Mac.mm index 0a6cb46a..6119e532 100644 --- a/lib/Support/Logging-Mac.mm +++ b/lib/Support/Logging-Mac.mm @@ -16,9 +16,11 @@ #import void IndexStoreDB::Log_impl(const char *loggerName, const char *message) { - // Using NSLog instead of stderr, to avoid interleaving with other log output in the process. - // NSLog also logs to asl. - NSLog(@"%s: %s", loggerName, message); + // Using NSLog instead of stderr, to avoid interleaving with other log output + // in the process. NSLog also logs to asl. Note that we need to print as an + // NSString here, since printing the C string with '%s' would use the default + // system encoding instead of UTF-8. + NSLog(@"%s: %@", loggerName, [NSString stringWithUTF8String:message]); } #endif