From 1ba2cee840613a4386f80189fce4169061cc6f40 Mon Sep 17 00:00:00 2001 From: culler Date: Sat, 9 Nov 2019 14:49:43 +0000 Subject: Fix [53d28027e3]: Generate an error instead of a crash if wm iconphoto receives an invalid photo image. --- macosx/tkMacOSXDraw.c | 7 +++++-- macosx/tkMacOSXWm.c | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c index 5714bf4..3f7ca0a 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 NULL; + } + 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 c2b67f6..40fca11 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -2569,6 +2569,10 @@ WmIconphotoCmd( width, height); Tk_FreeImage(tk_icon); if (newIcon == NULL) { + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "Failed to create an NSImage from \"%s\".", + icon)); + Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "PHOTO", NULL); return TCL_ERROR; } [NSApp setApplicationIconImage: newIcon]; -- cgit v0.12 From c6c3908ad15bb2ad9eb39b2b5177f601fe692d61 Mon Sep 17 00:00:00 2001 From: culler Date: Sun, 10 Nov 2019 18:13:49 +0000 Subject: Make all platforms check if an iconphoto image is valid and provide the same error message if not. --- macosx/tkMacOSXWm.c | 7 +++---- unix/tkUnixWm.c | 4 ++++ win/tkWinWm.c | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 40fca11..086746b 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -2569,10 +2569,9 @@ WmIconphotoCmd( width, height); Tk_FreeImage(tk_icon); if (newIcon == NULL) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "Failed to create an NSImage from \"%s\".", - icon)); - Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "PHOTO", 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/unix/tkUnixWm.c b/unix/tkUnixWm.c index bc7f1cb..b284622 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", "PHOTO", NULL); return TCL_ERROR; } Tk_PhotoGetSize(photo, &width, &height); diff --git a/win/tkWinWm.c b/win/tkWinWm.c index 117b539..d30152f 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; } -- cgit v0.12 From 2d08ff857a9a0a9afc14825e7d33208a115e38dd Mon Sep 17 00:00:00 2001 From: fvogel Date: Sun, 10 Nov 2019 20:03:21 +0000 Subject: Add platform-independent test wm-iconphoto-1.5 --- tests/wm.test | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/wm.test b/tests/wm.test index c2bc385..b5ef92a 100644 --- a/tests/wm.test +++ b/tests/wm.test @@ -873,6 +873,9 @@ 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 {usage} -returnCodes error -body { + wm iconphoto . -default [image create photo -file {}] +} -result {failed to create an iconphoto with image "image1"} # All other iconphoto tests are platform specific -- cgit v0.12 From c1711a576e24c000190039b0476642171a00736b Mon Sep 17 00:00:00 2001 From: fvogel Date: Sun, 10 Nov 2019 20:09:08 +0000 Subject: Homogenize still further among platforms --- unix/tkUnixWm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unix/tkUnixWm.c b/unix/tkUnixWm.c index b284622..e81aa58 100644 --- a/unix/tkUnixWm.c +++ b/unix/tkUnixWm.c @@ -2450,7 +2450,7 @@ WmIconphotoCmd( Tcl_SetObjResult(interp, Tcl_ObjPrintf( "failed to create an iconphoto with image \"%s\"", Tcl_GetString(objv[i]))); - Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "PHOTO", NULL); + Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "IMAGE", NULL); return TCL_ERROR; } Tk_PhotoGetSize(photo, &width, &height); -- cgit v0.12 From 00979fc3e90f332ebbdbea41c9efce20f422136e Mon Sep 17 00:00:00 2001 From: fvogel Date: Sun, 10 Nov 2019 21:11:10 +0000 Subject: The new test wm-iconphoto-1.5 must not depend on previous tests and how many images were created so far in the testing process --- tests/wm.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/wm.test b/tests/wm.test index b5ef92a..e290b8c 100644 --- a/tests/wm.test +++ b/tests/wm.test @@ -875,7 +875,7 @@ test wm-iconphoto-1.4 {usage} -returnCodes error -body { } -result {wrong # args: should be "wm iconphoto window ?-default? image1 ?image2 ...?"} test wm-iconphoto-1.5 {usage} -returnCodes error -body { wm iconphoto . -default [image create photo -file {}] -} -result {failed to create an iconphoto with image "image1"} +} -match {glob} -result {failed to create an iconphoto with image *} # All other iconphoto tests are platform specific -- cgit v0.12 From 9b325ebbd06b8857fffffe9107c87e993ca550a8 Mon Sep 17 00:00:00 2001 From: fvogel Date: Sun, 10 Nov 2019 22:30:12 +0000 Subject: Split wm-iconphoto-1.5 into the Win and Mac case on one hand (an error triggers), and the Linux case on the other hand (no error is produced, the image is valid and can be used as an iconphoto even if its size is 0x0) --- tests/wm.test | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/wm.test b/tests/wm.test index e290b8c..22cd2ea 100644 --- a/tests/wm.test +++ b/tests/wm.test @@ -873,9 +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 {usage} -returnCodes error -body { +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 -- cgit v0.12 From 770d3ab7c71b257d3aee36fbd5346a71be5df6dd Mon Sep 17 00:00:00 2001 From: culler Date: Mon, 11 Nov 2019 01:45:54 +0000 Subject: Allow creating 0x0 NSImages, which work e.g. in labels, just don't allow using them as iconphoto images. --- macosx/tkMacOSXDraw.c | 2 +- macosx/tkMacOSXWm.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c index 3f7ca0a..fb6a8a0 100644 --- a/macosx/tkMacOSXDraw.c +++ b/macosx/tkMacOSXDraw.c @@ -504,7 +504,7 @@ TkMacOSXGetNSImageWithTkImage( Pixmap pixmap; NSImage *nsImage; if (width == 0 | height == 0) { - return NULL; + 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); diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 086746b..0d49d74 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,10 +2564,11 @@ 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( -- cgit v0.12