]>
Commit | Line | Data |
---|---|---|
90dbba45 AG |
1 | To: vim-dev@vim.org |
2 | Subject: Patch 6.3.030 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=ISO-8859-1 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 6.3.030 | |
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 | |
18 | ||
19 | ||
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 | |
22 | *************** | |
23 | *** 749,754 **** | |
24 | --- 749,758 ---- | |
25 | ||
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); | |
32 | ||
33 | menu->id = gtk_toolbar_insert_item( | |
34 | toolbar, | |
35 | *************** | |
36 | *** 993,998 **** | |
37 | --- 997,1004 ---- | |
38 | ||
39 | # ifdef HAVE_GTK2 | |
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. */ | |
43 | # else | |
44 | tooltip = menu->strings[MENU_INDEX_TIP]; | |
45 | # endif | |
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 | |
48 | *************** | |
49 | *** 2467,2472 **** | |
50 | --- 2467,2502 ---- | |
51 | return 1 - dbcs_head_off(base, p); | |
52 | } | |
53 | ||
54 | + #if (defined(HAVE_GTK2) && defined(FEAT_TOOLBAR)) || defined(PROTO) | |
55 | + /* | |
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. | |
59 | + */ | |
60 | + int | |
61 | + utf_valid_string(s, end) | |
62 | + char_u *s; | |
63 | + char_u *end; | |
64 | + { | |
65 | + int l; | |
66 | + char_u *p = s; | |
67 | + | |
68 | + while (end == NULL ? *p != NUL : p < end) | |
69 | + { | |
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 */ | |
75 | + ++p; | |
76 | + while (--l > 0) | |
77 | + if ((*p++ & 0xc0) != 0x80) | |
78 | + return FALSE; /* invalid trail byte */ | |
79 | + } | |
80 | + return TRUE; | |
81 | + } | |
82 | + #endif | |
83 | + | |
84 | #if defined(FEAT_GUI) || defined(PROTO) | |
85 | /* | |
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 | |
89 | *************** | |
90 | *** 47,52 **** | |
91 | --- 47,53 ---- | |
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 | |
101 | *************** | |
102 | *** 6608,6616 **** | |
103 | len = screen_Columns; | |
104 | else | |
105 | len = Columns; | |
106 | ! mch_memmove(new_ScreenLines + new_LineOffset[new_row], | |
107 | ! ScreenLines + LineOffset[old_row], | |
108 | ! (size_t)len * sizeof(schar_T)); | |
109 | #ifdef FEAT_MBYTE | |
110 | if (enc_utf8 && ScreenLinesUC != NULL) | |
111 | { | |
112 | --- 6608,6621 ---- | |
113 | len = screen_Columns; | |
114 | else | |
115 | len = Columns; | |
116 | ! #ifdef FEAT_MBYTE | |
117 | ! /* When switching to utf-8 don't copy characters, they | |
118 | ! * may be invalid now. */ | |
119 | ! if (!(enc_utf8 && ScreenLinesUC == NULL)) | |
120 | ! #endif | |
121 | ! mch_memmove(new_ScreenLines + new_LineOffset[new_row], | |
122 | ! ScreenLines + LineOffset[old_row], | |
123 | ! (size_t)len * sizeof(schar_T)); | |
124 | #ifdef FEAT_MBYTE | |
125 | if (enc_utf8 && ScreenLinesUC != NULL) | |
126 | { | |
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 | |
129 | *************** | |
130 | *** 643,644 **** | |
131 | --- 643,646 ---- | |
132 | { /* Add new patch number below this line */ | |
133 | + /**/ | |
134 | + 30, | |
135 | /**/ | |
136 | ||
137 | -- | |
138 | From "know your smileys": | |
139 | :-E Has major dental problems | |
140 | ||
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 /// |