4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: GTK 2: Crash when sourcing a script that deletes the menus, sets
12 'encoding' to "utf-8" and loads the menus again. GTK error
13 message when tooltip text is in a wrong encoding.
14 Solution: Don't copy characters from the old screen to the new screen when
15 switching 'encoding' to utf-8, they may be invalid. Only set the
16 tooltip when it is valid utf-8.
17 Files: src/gui_gtk.c, src/mbyte.c, src/proto/mbyte.pro, src/screen.c
20 *** ../vim-6.3.029/src/gui_gtk.c Wed Jun 9 14:56:25 2004
21 --- src/gui_gtk.c Thu Oct 7 16:27:43 2004
26 text = CONVERT_TO_UTF8(menu->dname);
27 tooltip = CONVERT_TO_UTF8(menu->strings[MENU_INDEX_TIP]);
28 + if (tooltip != NULL && !utf_valid_string(tooltip, NULL))
29 + /* Invalid text, can happen when 'encoding' is changed. Avoid
30 + * a nasty GTK error message, skip the tooltip. */
31 + CONVERT_TO_UTF8_FREE(tooltip);
33 menu->id = gtk_toolbar_insert_item(
40 tooltip = CONVERT_TO_UTF8(menu->strings[MENU_INDEX_TIP]);
41 + if (tooltip == NULL || utf_valid_string(tooltip, NULL))
42 + /* Only set the tooltip when it's valid utf-8. */
44 tooltip = menu->strings[MENU_INDEX_TIP];
46 *** ../vim-6.3.029/src/mbyte.c Wed Jun 9 14:56:27 2004
47 --- src/mbyte.c Thu Oct 7 19:27:45 2004
51 return 1 - dbcs_head_off(base, p);
54 + #if (defined(HAVE_GTK2) && defined(FEAT_TOOLBAR)) || defined(PROTO)
56 + * Return TRUE if string "s" is a valid utf-8 string.
57 + * When "end" is NULL stop at the first NUL.
58 + * When "end" is positive stop there.
61 + utf_valid_string(s, end)
68 + while (end == NULL ? *p != NUL : p < end)
70 + if ((*p & 0xc0) == 0x80)
71 + return FALSE; /* invalid lead byte */
72 + l = utf8len_tab[*p];
73 + if (end != NULL && p + l > end)
74 + return FALSE; /* incomplete byte sequence */
77 + if ((*p++ & 0xc0) != 0x80)
78 + return FALSE; /* invalid trail byte */
84 #if defined(FEAT_GUI) || defined(PROTO)
86 * Special version of mb_tail_off() for use in ScreenLines[].
87 *** ../vim-6.3.029/src/proto/mbyte.pro Wed Jun 9 14:56:24 2004
88 --- src/proto/mbyte.pro Thu Oct 7 16:36:38 2004
92 int utf_head_off __ARGS((char_u *base, char_u *p));
93 int mb_off_next __ARGS((char_u *base, char_u *p));
94 int mb_tail_off __ARGS((char_u *base, char_u *p));
95 + int utf_valid_string __ARGS((char_u *s, char_u *end));
96 int dbcs_screen_tail_off __ARGS((char_u *base, char_u *p));
97 void mb_adjust_cursor __ARGS((void));
98 void mb_adjustpos __ARGS((pos_T *lp));
99 *** ../vim-6.3.029/src/screen.c Wed Jun 9 14:56:26 2004
100 --- src/screen.c Thu Oct 7 15:40:54 2004
103 len = screen_Columns;
106 ! mch_memmove(new_ScreenLines + new_LineOffset[new_row],
107 ! ScreenLines + LineOffset[old_row],
108 ! (size_t)len * sizeof(schar_T));
110 if (enc_utf8 && ScreenLinesUC != NULL)
113 len = screen_Columns;
117 ! /* When switching to utf-8 don't copy characters, they
118 ! * may be invalid now. */
119 ! if (!(enc_utf8 && ScreenLinesUC == NULL))
121 ! mch_memmove(new_ScreenLines + new_LineOffset[new_row],
122 ! ScreenLines + LineOffset[old_row],
123 ! (size_t)len * sizeof(schar_T));
125 if (enc_utf8 && ScreenLinesUC != NULL)
127 *** ../vim-6.3.029/src/version.c Tue Oct 5 17:02:41 2004
128 --- src/version.c Thu Oct 7 20:05:58 2004
132 { /* Add new patch number below this line */
138 From "know your smileys":
139 :-E Has major dental problems
141 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
142 /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
143 \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
144 \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///