diff options
author | Kevin Walzer <kw@codebykevin.com> | 2017-07-03 02:59:27 (GMT) |
---|---|---|
committer | Kevin Walzer <kw@codebykevin.com> | 2017-07-03 02:59:27 (GMT) |
commit | 4abdac47b667157cd88896d18468ea3c25235b00 (patch) | |
tree | 7a2f3b6d928e6da2577f719da7539b172580cfa7 | |
parent | 1abfb9b8018c02a8fa7623e6e54adf4266a70375 (diff) | |
download | tk-4abdac47b667157cd88896d18468ea3c25235b00.zip tk-4abdac47b667157cd88896d18468ea3c25235b00.tar.gz tk-4abdac47b667157cd88896d18468ea3c25235b00.tar.bz2 |
Fix for 8afc6c9ebe, crashes in save and open dialogs on macOS; thanks to Marc Simpson for bug report
-rw-r--r-- | macosx/tkMacOSXDialog.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c index 3397f71..9d78ce6 100644 --- a/macosx/tkMacOSXDialog.c +++ b/macosx/tkMacOSXDialog.c @@ -538,7 +538,7 @@ Tk_GetOpenFileObjCmd( if (len) { filename = [[[NSString alloc] initWithUTF8String:str] autorelease]; - [openpanel setNameFieldStringValue:filename]; + [openpanel setNameFieldStringValue:filename]; } break; case OPEN_MESSAGE: @@ -662,7 +662,12 @@ Tk_GetOpenFileObjCmd( if (directory) { [openpanel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]]; } + /*check for file name, otherwise set to empty string; crashes with uncaught exception if set to nil*/ + if (filename) { [openpanel setNameFieldStringValue:filename]; + } else { + [openpanel setNameFieldStringValue:@""]; + } [openpanel beginSheetModalForWindow:parent completionHandler:^(NSInteger returnCode) { [NSApp tkFilePanelDidEnd:openpanel @@ -678,7 +683,13 @@ Tk_GetOpenFileObjCmd( if (directory) { [openpanel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]]; } - [openpanel setNameFieldStringValue:filename]; + /*check for file name, otherwise set to empty string; crashes with uncaught exception if set to nil*/ + if (filename) { + [openpanel setNameFieldStringValue:filename]; + } else { + [openpanel setNameFieldStringValue:@""]; + } + modalReturnCode = [openpanel runModal]; #endif [NSApp tkFilePanelDidEnd:openpanel returnCode:modalReturnCode @@ -898,6 +909,12 @@ Tk_GetSaveFileObjCmd( if (directory) { [savepanel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]]; } + /*check for file name, otherwise set to empty string; crashes with uncaught exception if set to nil*/ + if (filename) { + [savepanel setNameFieldStringValue:filename]; + } else { + [savepanel setNameFieldStringValue:@""]; + } [savepanel setNameFieldStringValue:filename]; [savepanel beginSheetModalForWindow:parent completionHandler:^(NSInteger returnCode) @@ -913,7 +930,12 @@ Tk_GetSaveFileObjCmd( if (directory) { [savepanel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]]; } - [savepanel setNameFieldStringValue:filename]; + /*check for file name, otherwise set to empty string; crashes with uncaught exception if set to nil*/ + if (filename) { + [savepanel setNameFieldStringValue:filename]; + } else { + [savepanel setNameFieldStringValue:@""]; + } modalReturnCode = [savepanel runModal]; #if 0 NSLog(@"modal: %li", modalReturnCode); @@ -1047,6 +1069,10 @@ Tk_ChooseDirectoryObjCmd( callbackInfo->cmdObj = cmdObj; callbackInfo->interp = interp; callbackInfo->multiple = 0; + /*check for directory value, set to root if not specified; otherwise crashes with exception because of nil string parameter*/ + if (!directory) { + directory = @"/"; + } parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window); if (haveParentOption && parent && ![parent attachedSheet]) { parentIsKey = [parent isKeyWindow]; |