diff --git a/src/video/cocoa/SDL_cocoaclipboard.m b/src/video/cocoa/SDL_cocoaclipboard.m index a091d8feb..bfd35f055 100644 --- a/src/video/cocoa/SDL_cocoaclipboard.m +++ b/src/video/cocoa/SDL_cocoaclipboard.m @@ -32,10 +32,14 @@ Cocoa_SetClipboardText(_THIS, const char *text) 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; }} @@ -61,7 +65,7 @@ Cocoa_GetClipboardText(_THIS) } else { utf8 = [string UTF8String]; } - text = SDL_strdup(utf8); + text = SDL_strdup(utf8 ? utf8 : ""); } else { text = SDL_strdup(""); }