diff options
author | culler <culler> | 2019-09-22 03:09:53 (GMT) |
---|---|---|
committer | culler <culler> | 2019-09-22 03:09:53 (GMT) |
commit | 8c648e4de61beb5286b4bc2efdc087fb97185cac (patch) | |
tree | 22ac27985ba0fb9450653621d507ea0c4572210d | |
parent | cd10234e38f770e0ccb89282180716b4cbd04fea (diff) | |
download | tk-8c648e4de61beb5286b4bc2efdc087fb97185cac.zip tk-8c648e4de61beb5286b4bc2efdc087fb97185cac.tar.gz tk-8c648e4de61beb5286b4bc2efdc087fb97185cac.tar.bz2 |
Fix bug [96bce57407]: crash when drawing 1x1 rounded rectangles
-rw-r--r-- | macosx/tkMacOSXHLEvents.c | 1 | ||||
-rw-r--r-- | macosx/ttkMacOSXTheme.c | 27 |
2 files changed, 24 insertions, 4 deletions
diff --git a/macosx/tkMacOSXHLEvents.c b/macosx/tkMacOSXHLEvents.c index 42c15f4..7f038cf 100644 --- a/macosx/tkMacOSXHLEvents.c +++ b/macosx/tkMacOSXHLEvents.c @@ -147,7 +147,6 @@ static char* scriptTextProc = "::tk::mac::DoScriptText"; long count, index; AEKeyword keyword; Tcl_DString pathName; - int code; /* * Do nothing if we don't have an interpreter. diff --git a/macosx/ttkMacOSXTheme.c b/macosx/ttkMacOSXTheme.c index 66192ac..2cbaeaa 100644 --- a/macosx/ttkMacOSXTheme.c +++ b/macosx/ttkMacOSXTheme.c @@ -126,6 +126,19 @@ static CGFloat pressedPushButtonGradient[8] = { #define CGPathCreateWithRoundedRect(w, x, y, z) NULL #endif +/* + * If we try to draw a rounded rectangle with too large of a radius + * CoreGraphics will raise a fatal exception. This macro returns if + * the width or height is less than twice the radius. Presumably this + * only happens when a widget has not yet been configured and has size + * 1x1. + */ + +#define CHECK_RADIUS(radius, bounds) \ + if (radius > bounds.size.width / 2 || radius > bounds.size.height / 2) { \ + return; \ + } + /*---------------------------------------------------------------------- * +++ Utilities. */ @@ -381,6 +394,8 @@ static void FillButtonBackground( CGRect bounds, CGFloat radius) { + CHECK_RADIUS(radius, bounds) + CGPathRef path; NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; CGGradientRef backgroundGradient = CGGradientCreateWithColorComponents( @@ -389,7 +404,6 @@ static void FillButtonBackground( bounds.origin.x, bounds.origin.y + bounds.size.height }; - CGContextBeginPath(context); path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL); CGContextAddPath(context, path); @@ -443,6 +457,8 @@ static void DrawGroupBox( CGContextRef context, Tk_Window tkwin) { + CHECK_RADIUS(4, bounds) + CGPathRef path; NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; NSColor *borderColor, *bgColor; @@ -485,6 +501,7 @@ static void SolidFillRoundedRectangle( NSColor *color) { CGPathRef path; + CHECK_RADIUS(radius, bounds) CGContextSetFillColorWithColor(context, CGCOLOR(color)); path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL); @@ -605,6 +622,8 @@ static void GradientFillRoundedRectangle( { NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; CGPathRef path; + CHECK_RADIUS(radius, bounds) + CGPoint end = { bounds.origin.x, bounds.origin.y + bounds.size.height @@ -1043,6 +1062,9 @@ static void DrawDarkFocusRing( CGRect bounds, CGContextRef context) { + CGRect insetBounds = CGRectInset(bounds, -3, -3); + CHECK_RADIUS(4, insetBounds) + NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; NSColor *strokeColor; NSColor *fillColor = [NSColor colorWithColorSpace:deviceRGB @@ -1072,8 +1094,7 @@ static void DrawDarkFocusRing( CGContextStrokePath(context); CGContextSetShouldAntialias(context, true); CGContextSetFillColorWithColor(context, CGCOLOR(fillColor)); - CGPathRef path = CGPathCreateWithRoundedRect(CGRectInset(bounds, -3, -3), - 4, 4, NULL); + CGPathRef path = CGPathCreateWithRoundedRect(insetBounds, 4, 4, NULL); CGContextBeginPath(context); CGContextAddPath(context, path); CGContextAddRect(context, bounds); |