Skip to content

Commit a9be710

Browse files
committed
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
1 parent d873f38 commit a9be710

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/Support/Logging-Mac.mm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
#import <Foundation/Foundation.h>
1717

1818
void IndexStoreDB::Log_impl(const char *loggerName, const char *message) {
19-
// Using NSLog instead of stderr, to avoid interleaving with other log output in the process.
20-
// NSLog also logs to asl.
21-
NSLog(@"%s: %s", loggerName, message);
19+
// Using NSLog instead of stderr, to avoid interleaving with other log output
20+
// in the process. NSLog also logs to asl. Note that we need to need to
21+
// print as an NSString here, since printing the C string with '%s' would use
22+
// the default system encoding instead of UTF-8.
23+
NSLog(@"%s: %@", loggerName, [NSString stringWithUTF8String:message]);
2224
}
2325

2426
#endif

0 commit comments

Comments
 (0)