summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorculler <culler>2019-09-24 02:33:08 (GMT)
committerculler <culler>2019-09-24 02:33:08 (GMT)
commit0de78ce9ce43fcfbe9fe16cb0cb36f6cfa9b6e07 (patch)
treefe7822bbf08b7707903c94d9f062d45f40787ea0
parent7fde7668768f30358cead45f0f0c3b12f190fd04 (diff)
parentaeb98f3a5488e637486a6b376b172de8a658d4b9 (diff)
downloadtk-0de78ce9ce43fcfbe9fe16cb0cb36f6cfa9b6e07.zip
tk-0de78ce9ce43fcfbe9fe16cb0cb36f6cfa9b6e07.tar.gz
tk-0de78ce9ce43fcfbe9fe16cb0cb36f6cfa9b6e07.tar.bz2
Fix bug [96bce57407]: macosx crash when drawing 1x1 rounded rectangles.
-rw-r--r--macosx/tkMacOSXHLEvents.c1
-rw-r--r--macosx/ttkMacOSXTheme.c27
2 files changed, 24 insertions, 4 deletions
diff --git a/macosx/tkMacOSXHLEvents.c b/macosx/tkMacOSXHLEvents.c
index 9c8c515..0c7eb67 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 47624df..60e768d 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);