summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorculler <culler>2019-11-17 17:11:04 (GMT)
committerculler <culler>2019-11-17 17:11:04 (GMT)
commit5bc76fef182c52a50e34b7f95c43f194ea8711fe (patch)
treee490d8b8b3f4aaee73df06d359836ef9fb60f7d8
parent1dcfa065cbd9c94750fabda9313008e76e4d9c87 (diff)
parent770d3ab7c71b257d3aee36fbd5346a71be5df6dd (diff)
downloadtk-5bc76fef182c52a50e34b7f95c43f194ea8711fe.zip
tk-5bc76fef182c52a50e34b7f95c43f194ea8711fe.tar.gz
tk-5bc76fef182c52a50e34b7f95c43f194ea8711fe.tar.bz2
Fix [53d28027e3]: macOS crashes with 0x0 image for wm iconphoto; make wm iconphoto behavior consistent between platforms.
-rw-r--r--macosx/tkMacOSXDraw.c7
-rw-r--r--macosx/tkMacOSXWm.c11
-rw-r--r--tests/wm.test6
-rw-r--r--unix/tkUnixWm.c4
-rw-r--r--win/tkWinWm.c4
5 files changed, 25 insertions, 7 deletions
diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c
index f4c0107..f19198d 100644
--- a/macosx/tkMacOSXDraw.c
+++ b/macosx/tkMacOSXDraw.c
@@ -501,9 +501,12 @@ TkMacOSXGetNSImageWithTkImage(
int width,
int height)
{
- Pixmap pixmap = Tk_GetPixmap(display, None, width, height, 0);
+ Pixmap pixmap;
NSImage *nsImage;
-
+ if (width == 0 | height == 0) {
+ return nsImage = [[NSImage alloc] initWithSize:NSMakeSize(0,0)];
+ }
+ pixmap = Tk_GetPixmap(display, None, width, height, 0);
Tk_RedrawImage(image, 0, 0, width, height, pixmap, 0, 0);
nsImage = CreateNSImageWithPixmap(pixmap, width, height);
Tk_FreePixmap(display, pixmap);
diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c
index 53bb400..ceb3f3f 100644
--- a/macosx/tkMacOSXWm.c
+++ b/macosx/tkMacOSXWm.c
@@ -2518,6 +2518,7 @@ WmIconphotoCmd(
{
Tk_Image tk_icon;
int width, height, isDefault = 0;
+ NSImage *newIcon = NULL;
if (objc < 4) {
Tcl_WrongNumArgs(interp, 2, objv,
@@ -2563,12 +2564,16 @@ WmIconphotoCmd(
return TCL_ERROR;
}
- NSImage *newIcon;
Tk_SizeOfImage(tk_icon, &width, &height);
- newIcon = TkMacOSXGetNSImageWithTkImage(winPtr->display, tk_icon,
- width, height);
+ if (width != 0 && height != 0) {
+ newIcon = TkMacOSXGetNSImageWithTkImage(winPtr->display, tk_icon,
+ width, height);
+ }
Tk_FreeImage(tk_icon);
if (newIcon == NULL) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "failed to create an iconphoto with image \"%s\"", icon));
+ Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "IMAGE", NULL);
return TCL_ERROR;
}
[NSApp setApplicationIconImage: newIcon];
diff --git a/tests/wm.test b/tests/wm.test
index 1dbc372..4d0d73b 100644
--- a/tests/wm.test
+++ b/tests/wm.test
@@ -873,6 +873,12 @@ test wm-iconphoto-1.4 {usage} -returnCodes error -body {
# we currently have no return info
wm iconphoto . -default
} -result {wrong # args: should be "wm iconphoto window ?-default? image1 ?image2 ...?"}
+test wm-iconphoto-1.5.1 {usage} -constraints aquaOrWin32 -returnCodes error -body {
+ wm iconphoto . -default [image create photo -file {}]
+} -match {glob} -result {failed to create an iconphoto with image *}
+test wm-iconphoto-1.5.2 {usage} -constraints x11 -body {
+ wm iconphoto . -default [image create photo -file {}]
+} -result {}
# All other iconphoto tests are platform specific
diff --git a/unix/tkUnixWm.c b/unix/tkUnixWm.c
index 0ebd4ac..2c9e9dd 100644
--- a/unix/tkUnixWm.c
+++ b/unix/tkUnixWm.c
@@ -2447,6 +2447,10 @@ WmIconphotoCmd(
photo = Tk_FindPhoto(interp, Tcl_GetString(objv[i]));
if (photo == NULL) {
ckfree((char *) iconPropertyData);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "failed to create an iconphoto with image \"%s\"",
+ Tcl_GetString(objv[i])));
+ Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "IMAGE", NULL);
return TCL_ERROR;
}
Tk_PhotoGetSize(photo, &width, &height);
diff --git a/win/tkWinWm.c b/win/tkWinWm.c
index 7df5dcf..bddbe05 100644
--- a/win/tkWinWm.c
+++ b/win/tkWinWm.c
@@ -4384,9 +4384,9 @@ WmIconphotoCmd(
if (!iconInfo.hbmColor) {
ckfree(lpIR);
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "failed to create color bitmap for \"%s\"",
+ "failed to create an iconphoto with image \"%s\"",
Tcl_GetString(objv[i])));
- Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "BITMAP", NULL);
+ Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "IMAGE", NULL);
return TCL_ERROR;
}