summaryrefslogtreecommitdiffstats
path: root/unix/tkUnixMenu.c
diff options
context:
space:
mode:
authorhobbs <hobbs>2006-11-24 18:11:54 (GMT)
committerhobbs <hobbs>2006-11-24 18:11:54 (GMT)
commit9f5ab5519d8485a222584d78d91754615086f01b (patch)
treef4cdeee107ef79f75ddfe6685b0f10eb03a0b3f2 /unix/tkUnixMenu.c
parent9efa47af7492a545605cadcbceda5b7b69d0870b (diff)
downloadtk-9f5ab5519d8485a222584d78d91754615086f01b.zip
tk-9f5ab5519d8485a222584d78d91754615086f01b.tar.gz
tk-9f5ab5519d8485a222584d78d91754615086f01b.tar.bz2
* unix/tkUnixMenu.c (DrawMenuUnderline): bound Tcl_UtfAtIndex usage
* tests/menu.test (menu-36.1): [Bug 1599877]
Diffstat (limited to 'unix/tkUnixMenu.c')
-rw-r--r--unix/tkUnixMenu.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/unix/tkUnixMenu.c b/unix/tkUnixMenu.c
index cec9ad6..a3a0c75 100644
--- a/unix/tkUnixMenu.c
+++ b/unix/tkUnixMenu.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkUnixMenu.c,v 1.7.2.1 2004/05/03 23:23:42 hobbs Exp $
+ * RCS: @(#) $Id: tkUnixMenu.c,v 1.7.2.2 2006/11/24 18:11:54 hobbs Exp $
*/
#include "tkPort.h"
@@ -884,26 +884,32 @@ DrawMenuUnderline(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
int width;
int height;
{
- int indicatorSpace = mePtr->indicatorSpace;
+ if ((mePtr->underline >= 0) && (mePtr->labelPtr != NULL)) {
+ int len;
- if (mePtr->underline >= 0) {
- int activeBorderWidth;
- int leftEdge;
- char *label = Tcl_GetStringFromObj(mePtr->labelPtr, NULL);
- CONST char *start = Tcl_UtfAtIndex(label, mePtr->underline);
- CONST char *end = Tcl_UtfNext(start);
+ /* do the unicode call just to prevent overruns */
+ Tcl_GetUnicodeFromObj(mePtr->labelPtr, &len);
+ if (mePtr->underline < len) {
+ int activeBorderWidth;
+ int leftEdge;
+ CONST char *label, *start, *end;
- Tk_GetPixelsFromObj(NULL, menuPtr->tkwin,
- menuPtr->activeBorderWidthPtr, &activeBorderWidth);
- leftEdge = x + indicatorSpace + activeBorderWidth;
- if (menuPtr->menuType == MENUBAR) {
- leftEdge += 5;
- }
+ label = Tcl_GetStringFromObj(mePtr->labelPtr, NULL);
+ start = Tcl_UtfAtIndex(label, mePtr->underline);
+ end = Tcl_UtfNext(start);
- Tk_UnderlineChars(menuPtr->display, d, gc, tkfont, label,
- leftEdge, y + (height + fmPtr->ascent - fmPtr->descent) / 2,
- start - label, end - label);
- }
+ Tk_GetPixelsFromObj(NULL, menuPtr->tkwin,
+ menuPtr->activeBorderWidthPtr, &activeBorderWidth);
+ leftEdge = x + mePtr->indicatorSpace + activeBorderWidth;
+ if (menuPtr->menuType == MENUBAR) {
+ leftEdge += 5;
+ }
+
+ Tk_UnderlineChars(menuPtr->display, d, gc, tkfont, label, leftEdge,
+ y + (height + fmPtr->ascent - fmPtr->descent) / 2,
+ start - label, end - label);
+ }
+ }
}
/*