summaryrefslogtreecommitdiff
path: root/src/os/macosx
diff options
context:
space:
mode:
authoruvealonso <39194608+uvealonso@users.noreply.github.com>2019-08-25 23:01:33 +0100
committerMichael Lutz <michi@icosahedron.de>2019-09-01 14:01:52 +0200
commitead772324e0fb9df502022397d06150c218c9d21 (patch)
treecc0f62afae35cd9ab99954199aadf025713df398 /src/os/macosx
parenta933afabfda2986f88e27ea512253227cc629252 (diff)
downloadopenttd-ead772324e0fb9df502022397d06150c218c9d21.tar.xz
Fix #7704: [OSX] Handle malformed UTF8 strings
Diffstat (limited to 'src/os/macosx')
-rw-r--r--src/os/macosx/string_osx.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp
index 6d90b91a8..4c33d5497 100644
--- a/src/os/macosx/string_osx.cpp
+++ b/src/os/macosx/string_osx.cpp
@@ -306,6 +306,13 @@ int MacOSStringCompare(const char *s1, const char *s2)
CFStringRef cf1 = CFStringCreateWithCString(kCFAllocatorDefault, s1, kCFStringEncodingUTF8);
CFStringRef cf2 = CFStringCreateWithCString(kCFAllocatorDefault, s2, kCFStringEncodingUTF8);
+ /* If any CFString could not be created (e.g., due to UTF8 invalid chars), return OS unsupported functionality */
+ if (cf1 == nullptr || cf2 == nullptr) {
+ if (cf1 != nullptr) CFRelease(cf1);
+ if (cf2 != nullptr) CFRelease(cf2);
+ return 0;
+ }
+
CFComparisonResult res = CFStringCompareWithOptionsAndLocale(cf1, cf2, CFRangeMake(0, CFStringGetLength(cf1)), flags, _osx_locale);
CFRelease(cf1);