From 4924d7ef707ae1f08e43f05195a9d9454fc9966a Mon Sep 17 00:00:00 2001 From: marc_culler Date: Wed, 27 Jan 2021 20:38:50 +0000 Subject: Fix [bdcab85b9c]: Aqua crash when non-BMP characters are used in a menu label --- library/demos/menu.tcl | 2 ++ macosx/tkMacOSXMenu.c | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/library/demos/menu.tcl b/library/demos/menu.tcl index 62991f3..244361d 100644 --- a/library/demos/menu.tcl +++ b/library/demos/menu.tcl @@ -134,6 +134,8 @@ menu $m -tearoff 0 foreach i {{An entry} {Another entry} {Does nothing} {Does almost nothing} {Make life meaningful}} { $m add command -label $i -command [list puts "You invoked \"$i\""] } +set emojiLabel [encoding convertfrom utf-8 "\xF0\x9F\x98\x8D Make friends"] +$m add command -label $emojiLabel -command [list puts "Menu labels can include non-BMP characters."] $m entryconfigure "Does almost nothing" -bitmap questhead -compound left \ -command [list \ tk_dialog $w.compound {Compound Menu Entry} \ diff --git a/macosx/tkMacOSXMenu.c b/macosx/tkMacOSXMenu.c index 0604708..8c7ef52 100644 --- a/macosx/tkMacOSXMenu.c +++ b/macosx/tkMacOSXMenu.c @@ -708,9 +708,14 @@ TkpConfigureMenuEntry( [menuItem setImage:image]; if ((!image || mePtr->compound != COMPOUND_NONE) && mePtr->labelPtr && mePtr->labelLength) { - title = [[[NSString alloc] initWithBytes:Tcl_GetString(mePtr->labelPtr) - length:mePtr->labelLength encoding:NSUTF8StringEncoding] - autorelease]; + Tcl_DString ds; + Tcl_DStringInit(&ds); + Tcl_UtfToUniCharDString(Tcl_GetString(mePtr->labelPtr), + mePtr->labelLength, &ds); + title = [[NSString alloc] + initWithCharacters:(unichar *)Tcl_DStringValue(&ds) + length:Tcl_DStringLength(&ds)>>1]; + Tcl_DStringFree(&ds); if ([title hasSuffix:@"..."]) { title = [NSString stringWithFormat:@"%@%C", [title substringToIndex:[title length] - 3], 0x2026]; -- cgit v0.12