From 2156b8f27a1daba1ff6be50810e837283b9ec589 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 1 Dec 2019 16:05:17 +0000 Subject: In tkUnixFont, make sure that the utf-to-ucs2 encoder clamps at 0xFFFF. Use more uppercase hex-values where appropriate. --- changes | 4 ++-- generic/tkUtil.c | 2 +- unix/tkUnixColor.c | 10 +++++----- unix/tkUnixFont.c | 21 ++++++++++++--------- unix/tkUnixMenu.c | 2 +- unix/tkUnixRFont.c | 2 +- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/changes b/changes index aea39f3..86e997d 100644 --- a/changes +++ b/changes @@ -7572,9 +7572,9 @@ Tk Cocoa 2.0: More drawing internals refinements (culler,walzer) 2018-11-19 (bug)[0a9c91] crash in text-11a.22 (vogel) -2018-11-20 (bug)[9705d1] crash activating "Alt" theme (culler) +2018-11-20 (bug)[9705d1] crash activating "Alt" theme (culler) -2018-11-24 (bug)[e3b954] cursor offset at full screen display (culler) +2018-11-24 (bug)[e3b954] cursor offset at full screen display (culler) 2019-01-04 (bug)[18a4ba] cross-platform [winfo containing] (culler) diff --git a/generic/tkUtil.c b/generic/tkUtil.c index 38f71ea..1a1efa1 100644 --- a/generic/tkUtil.c +++ b/generic/tkUtil.c @@ -1222,7 +1222,7 @@ TkUtfToUniChar( Tcl_UniChar uniChar = 0; int len = Tcl_UtfToUniChar(src, &uniChar); - if ((uniChar & 0xFC00) == 0xD800) { + if ((sizeof(Tcl_UniChar) == 2) && ((uniChar & 0xFC00) == 0xD800)) { Tcl_UniChar low = uniChar; /* This can only happen if Tcl is compiled with TCL_UTF_MAX=4, * or when a high surrogate character is detected in UTF-8 form */ diff --git a/unix/tkUnixColor.c b/unix/tkUnixColor.c index 512b20c..96e8937 100644 --- a/unix/tkUnixColor.c +++ b/unix/tkUnixColor.c @@ -136,17 +136,17 @@ TkpGetColor( if (*name != '#') { XColor screen; - if (((*name - 'A') & 0xdf) < sizeof(tkWebColors)/sizeof(tkWebColors[0])) { - if (!((name[0] - 'G') & 0xdf) && !((name[1] - 'R') & 0xdf) - && !((name[2] - 'A') & 0xdb) && !((name[3] - 'Y') & 0xdf) + if (((*name - 'A') & 0xDF) < sizeof(tkWebColors)/sizeof(tkWebColors[0])) { + if (!((name[0] - 'G') & 0xDF) && !((name[1] - 'R') & 0xDF) + && !((name[2] - 'A') & 0xDB) && !((name[3] - 'Y') & 0xDF) && !name[4]) { name = "#808080808080"; goto gotWebColor; } else { - const char *p = tkWebColors[((*name - 'A') & 0x1f)]; + const char *p = tkWebColors[((*name - 'A') & 0x1F)]; if (p) { const char *q = name; - while (!((*p - *(++q)) & 0xdf)) { + while (!((*p - *(++q)) & 0xDF)) { if (!*p++) { name = p; goto gotWebColor; diff --git a/unix/tkUnixFont.c b/unix/tkUnixFont.c index 3893a0a..d95527b 100644 --- a/unix/tkUnixFont.c +++ b/unix/tkUnixFont.c @@ -415,15 +415,15 @@ ControlUtfProc( dst += 2; } else if ((size_t)ch < 256) { dst[1] = 'x'; - dst[2] = hexChars[(ch >> 4) & 0xf]; - dst[3] = hexChars[ch & 0xf]; + dst[2] = hexChars[(ch >> 4) & 0xF]; + dst[3] = hexChars[ch & 0xF]; dst += 4; } else if ((size_t)ch < 0x10000) { dst[1] = 'u'; - dst[2] = hexChars[(ch >> 12) & 0xf]; - dst[3] = hexChars[(ch >> 8) & 0xf]; - dst[4] = hexChars[(ch >> 4) & 0xf]; - dst[5] = hexChars[ch & 0xf]; + dst[2] = hexChars[(ch >> 12) & 0xF]; + dst[3] = hexChars[(ch >> 8) & 0xF]; + dst[4] = hexChars[(ch >> 4) & 0xF]; + dst[5] = hexChars[ch & 0xF]; dst += 6; } else { /* TODO we can do better here */ @@ -610,13 +610,16 @@ UtfToUcs2beProc( break; } src += TkUtfToUniChar(src, &ch); + if (ch > 0xFFFF) { + ch = 0xFFFD; + } /* * Ensure big-endianness (store big bits first). */ - *dst++ = (char)(ch >> 8); - *dst++ = (char)ch; + *dst++ = (char)((ch >> 8) & 0xFF); + *dst++ = (char)(ch & 0xFF); } *srcReadPtr = src - srcStart; *dstWrotePtr = dst - dstStart; @@ -1977,7 +1980,7 @@ FindSubFontForChar( Tcl_DString ds; if (ch < 0 || ch > 0x30000) { - ch = 0xfffd; + ch = 0xFFFD; } for (i = 0; i < fontPtr->numSubFonts; i++) { diff --git a/unix/tkUnixMenu.c b/unix/tkUnixMenu.c index 909276a..f7e1860 100644 --- a/unix/tkUnixMenu.c +++ b/unix/tkUnixMenu.c @@ -1111,7 +1111,7 @@ TkpComputeMenubarGeometry( maxWindowWidth = Tk_Width(menuPtr->tkwin); if (maxWindowWidth == 1) { - maxWindowWidth = 0x7ffffff; + maxWindowWidth = 0x7FFFFFF; } currentRowHeight = 0; Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->borderWidthPtr, diff --git a/unix/tkUnixRFont.c b/unix/tkUnixRFont.c index 31b28c5..f2bef2b 100644 --- a/unix/tkUnixRFont.c +++ b/unix/tkUnixRFont.c @@ -832,7 +832,7 @@ LookUpColor(Display *display, /* Display to lookup colors on */ fontPtr->colors[last].color.color.red = xcolor.red; fontPtr->colors[last].color.color.green = xcolor.green; fontPtr->colors[last].color.color.blue = xcolor.blue; - fontPtr->colors[last].color.color.alpha = 0xffff; + fontPtr->colors[last].color.color.alpha = 0xFFFF; fontPtr->colors[last].color.pixel = pixel; /* -- cgit v0.12