Skip to content

Commit 94044d0

Browse files
author
culler
committed
merge bug-080a28104e: Fixes crash caused by nil UTType when user provides a bogus file type.
2 parents 5bde407 + dd5ca5f commit 94044d0

File tree

5 files changed

+81
-3
lines changed

5 files changed

+81
-3
lines changed

macosx/tkMacOSXDialog.c

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ static void setAllowedFileTypes(
3737
NSMutableArray<UTType *> *allowedTypes = [NSMutableArray array];
3838
for (NSString *ext in extensions) {
3939
UTType *uttype = [UTType typeWithFilenameExtension: ext];
40-
[allowedTypes addObject:uttype];
40+
if (uttype) {
41+
[allowedTypes addObject:uttype];
42+
}
4143
}
4244
[panel setAllowedContentTypes:allowedTypes];
4345
} else {
@@ -85,6 +87,41 @@ static filepanelFilterInfo filterInfo;
8587
static NSOpenPanel *openpanel;
8688
static NSSavePanel *savepanel;
8789

90+
/*
91+
* A thread which closes the currently running modal dialog after a timeout.
92+
*/
93+
94+
@interface TKPanelMonitor: NSThread {
95+
@private
96+
NSTimeInterval _timeout;
97+
}
98+
99+
- (id) initWithTimeout: (NSTimeInterval) timeout;
100+
101+
@end
102+
103+
@implementation TKPanelMonitor: NSThread
104+
105+
- (id) initWithTimeout: (NSTimeInterval) timeout {
106+
self = [super init];
107+
if (self) {
108+
_timeout = timeout;
109+
return self;
110+
}
111+
return self;
112+
}
113+
114+
- (void) main
115+
{
116+
[NSThread sleepForTimeInterval:_timeout];
117+
if ([self isCancelled]) {
118+
[NSThread exit];
119+
}
120+
[NSApp stopModalWithCode:modalCancel];
121+
}
122+
@end
123+
124+
88125
static const char *const colorOptionStrings[] = {
89126
"-initialcolor", "-parent", "-title", NULL
90127
};
@@ -868,7 +905,20 @@ Tk_GetOpenFileObjCmd(
868905
parent = nil;
869906
parentIsKey = False;
870907
}
871-
modalReturnCode = showOpenSavePanel(openpanel, parent, interp, cmdObj, multiple);
908+
TKPanelMonitor *monitor;
909+
if (testsAreRunning) {
910+
/*
911+
* We need the panel to close by itself when running tests.
912+
*/
913+
914+
monitor = [[TKPanelMonitor alloc] initWithTimeout: 1.0];
915+
[monitor start];
916+
}
917+
modalReturnCode = showOpenSavePanel(openpanel, parent, interp, cmdObj,
918+
multiple);
919+
if (testsAreRunning) {
920+
[monitor cancel];
921+
}
872922
if (cmdObj) {
873923
Tcl_DecrRefCount(cmdObj);
874924
}

macosx/tkMacOSXInit.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
#include <sys/stat.h>
2222
#include <sys/utsname.h>
2323

24+
/*
25+
* This flag is set if tests are being run.
26+
*/
27+
28+
int testsAreRunning = 0;
29+
2430
static char tkLibPath[PATH_MAX + 1] = "";
2531

2632
/*
@@ -45,6 +51,7 @@ static Tcl_ObjCmdProc TkMacOSVersionObjCmd;
4551
@synthesize tkLiveResizeEnded = _tkLiveResizeEnded;
4652
@synthesize tkWillExit = _tkWillExit;
4753
@synthesize tkPointerWindow = _tkPointerWindow;
54+
4855
- (void) setTkPointerWindow: (TkWindow *)winPtr
4956
{
5057
if (winPtr) {

macosx/tkMacOSXPrivate.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@
134134
STRINGIFY(symbol)); \
135135
}
136136

137+
/*
138+
* This is set to 1 if tests are being run. Defined in tkMacOSXInit.c.
139+
*/
140+
141+
extern int testsAreRunning;
142+
137143
/*
138144
* The structure of a 32-bit XEvent keycode on macOS. It may be viewed as
139145
* an unsigned int or as having either two or three bitfields.

macosx/tkMacOSXTest.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "tkMacOSXConstants.h"
1717
#include "tkMacOSXWm.h"
1818

19-
2019
/*
2120
* Forward declarations of procedures defined later in this file:
2221
*/
@@ -48,6 +47,12 @@ int
4847
TkplatformtestInit(
4948
Tcl_Interp *interp) /* Interpreter to add commands to. */
5049
{
50+
/*
51+
* Set a flag indicating that testing is in progress.
52+
*/
53+
54+
testsAreRunning = 1;
55+
5156
/*
5257
* Add commands for platform specific tests on MacOS here.
5358
*/

tests/filebox.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ test fileDialog-0.2 {GetFileName: file types: MakeFilter() fails} {
2323
regsub -all "\0" $msg {\\0} msg
2424
list $x $msg
2525
} {1 {bad Macintosh file type "\0\0"}}
26+
test fileDialog-0.3 {GetFileName: file types: bad filetype} \
27+
-constraints {[tk windowingsystem] eq "aqua"} \
28+
-body {
29+
# Check for the Aqua crash reported in ticket 080a28104.
30+
31+
set filename [tk_getOpenFile -filetypes {
32+
{"Invalid extension" {x.y}}
33+
{"All files" {*}}
34+
}]
35+
} -result {}
2636

2737
set tk_strictMotif_old $tk_strictMotif
2838

0 commit comments

Comments
 (0)