Skip to content

Commit

Permalink
cocoa: Report an error if SDL_SetClipboardText() isn't using UTF-8 en…
Browse files Browse the repository at this point in the history
…coding.

Fixes #4110.
  • Loading branch information
icculus committed May 8, 2021
1 parent 107db2d commit 9dc97af
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/video/cocoa/SDL_cocoaclipboard.m
Expand Up @@ -32,10 +32,14 @@
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
NSPasteboard *pasteboard;
NSString *format = NSPasteboardTypeString;
NSString *nsstr = [NSString stringWithUTF8String:text];
if (nsstr == nil) {
return SDL_SetError("Couldn't create NSString; is your string data in UTF-8 format?");
}

pasteboard = [NSPasteboard generalPasteboard];
data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
[pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
[pasteboard setString:nsstr forType:format];

return 0;
}}
Expand All @@ -61,7 +65,7 @@
} else {
utf8 = [string UTF8String];
}
text = SDL_strdup(utf8);
text = SDL_strdup(utf8 ? utf8 : "");
} else {
text = SDL_strdup("");
}
Expand Down

0 comments on commit 9dc97af

Please sign in to comment.