4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: Reading past end of a screen line when determining cell width.
13 Solution: Add an argument to mb_off2cells() for the maximum offset.
14 Files: src/globals.h, src/gui.c, src/mbyte.c, src/proto/mbyte.pro,
18 *** ../vim-7.1.092/src/globals.h Thu Aug 30 12:24:21 2007
19 --- src/globals.h Wed Aug 29 22:27:45 2007
22 EXTERN int (*mb_char2bytes) __ARGS((int c, char_u *buf)) INIT(= latin_char2bytes);
23 EXTERN int (*mb_ptr2cells) __ARGS((char_u *p)) INIT(= latin_ptr2cells);
24 EXTERN int (*mb_char2cells) __ARGS((int c)) INIT(= latin_char2cells);
25 ! EXTERN int (*mb_off2cells) __ARGS((unsigned off)) INIT(= latin_off2cells);
26 EXTERN int (*mb_ptr2char) __ARGS((char_u *p)) INIT(= latin_ptr2char);
27 EXTERN int (*mb_head_off) __ARGS((char_u *base, char_u *p)) INIT(= latin_head_off);
30 EXTERN int (*mb_char2bytes) __ARGS((int c, char_u *buf)) INIT(= latin_char2bytes);
31 EXTERN int (*mb_ptr2cells) __ARGS((char_u *p)) INIT(= latin_ptr2cells);
32 EXTERN int (*mb_char2cells) __ARGS((int c)) INIT(= latin_char2cells);
33 ! EXTERN int (*mb_off2cells) __ARGS((unsigned off, unsigned max_off)) INIT(= latin_off2cells);
34 EXTERN int (*mb_ptr2char) __ARGS((char_u *p)) INIT(= latin_ptr2char);
35 EXTERN int (*mb_head_off) __ARGS((char_u *base, char_u *p)) INIT(= latin_head_off);
37 *** ../vim-7.1.092/src/gui.c Wed Aug 15 20:07:53 2007
38 --- src/gui.c Wed Aug 29 22:16:51 2007
41 cur_width = gui.char_width;
44 ! if (has_mbyte && (*mb_off2cells)(LineOffset[gui.row] + gui.col) > 1)
46 /* Double wide character. */
47 if (shape_table[idx].shape != SHAPE_VER)
49 cur_width = gui.char_width;
52 ! if (has_mbyte && (*mb_off2cells)(LineOffset[gui.row] + gui.col,
53 ! LineOffset[gui.row] + screen_Columns) > 1)
55 /* Double wide character. */
56 if (shape_table[idx].shape != SHAPE_VER)
61 # if defined(FEAT_GUI_TABLINE) && (defined(FEAT_GUI_MSWIN) \
62 ! || defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_MAC))
63 if (gui_has_tabline())
64 text_area_y += gui.tabline_height;
69 # if defined(FEAT_GUI_TABLINE) && (defined(FEAT_GUI_MSWIN) \
70 ! || defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_MAC))
71 if (gui_has_tabline())
72 text_area_y += gui.tabline_height;
74 *** ../vim-7.1.092/src/mbyte.c Sat Aug 11 13:57:31 2007
75 --- src/mbyte.c Thu Aug 30 13:48:30 2007
79 * mb_off2cells() function pointer.
80 * Return number of display cells for char at ScreenLines[off].
81 ! * Caller must make sure "off" and "off + 1" are valid!
85 ! latin_off2cells(off)
95 /* Number of cells is equal to number of bytes, except for euc-jp when
96 * the first byte is 0x8e. */
97 if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e)
100 * mb_off2cells() function pointer.
101 * Return number of display cells for char at ScreenLines[off].
102 ! * We make sure that the offset used is less than "max_off".
106 ! latin_off2cells(off, max_off)
114 ! dbcs_off2cells(off, max_off)
118 + /* never check beyond end of the line */
119 + if (off >= max_off)
122 /* Number of cells is equal to number of bytes, except for euc-jp when
123 * the first byte is 0x8e. */
124 if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e)
133 ! return ScreenLines[off + 1] == 0 ? 2 : 1;
141 ! utf_off2cells(off, max_off)
145 ! return (off + 1 < max_off && ScreenLines[off + 1] == 0) ? 2 : 1;
151 if (composing_hangul)
155 ! return dbcs_off2cells(LineOffset[row] + col) > 1;
157 ! return (col + 1 < Columns
158 ! && ScreenLines[LineOffset[row] + col + 1] == 0);
162 # if defined(FEAT_CLIPBOARD) || defined(FEAT_GUI) || defined(FEAT_RIGHTLEFT) \
164 if (composing_hangul)
167 ! return (*mb_off2cells)(LineOffset[row] + col,
168 ! LineOffset[row] + screen_Columns) > 1;
171 # if defined(FEAT_CLIPBOARD) || defined(FEAT_GUI) || defined(FEAT_RIGHTLEFT) \
172 *** ../vim-7.1.092/src/proto/mbyte.pro Sat May 5 20:02:52 2007
173 --- src/proto/mbyte.pro Wed Aug 29 20:49:02 2007
176 int utf_ptr2cells __ARGS((char_u *p));
177 int dbcs_ptr2cells __ARGS((char_u *p));
178 int latin_char2cells __ARGS((int c));
179 ! int latin_off2cells __ARGS((unsigned off));
180 ! int dbcs_off2cells __ARGS((unsigned off));
181 ! int utf_off2cells __ARGS((unsigned off));
182 int latin_ptr2char __ARGS((char_u *p));
183 int utf_ptr2char __ARGS((char_u *p));
184 int mb_ptr2char_adv __ARGS((char_u **pp));
186 int utf_ptr2cells __ARGS((char_u *p));
187 int dbcs_ptr2cells __ARGS((char_u *p));
188 int latin_char2cells __ARGS((int c));
189 ! int latin_off2cells __ARGS((unsigned off, unsigned max_off));
190 ! int dbcs_off2cells __ARGS((unsigned off, unsigned max_off));
191 ! int utf_off2cells __ARGS((unsigned off, unsigned max_off));
192 int latin_ptr2char __ARGS((char_u *p));
193 int utf_ptr2char __ARGS((char_u *p));
194 int mb_ptr2char_adv __ARGS((char_u **pp));
195 *** ../vim-7.1.092/src/screen.c Sun Aug 5 20:10:16 2007
196 --- src/screen.c Thu Aug 30 10:31:26 2007
202 ! /* Trick: we want to avoid clearning the screen twice. screenclear() will
203 * set "screen_cleared" to TRUE. The special value MAYBE (which is still
204 * non-zero and thus not FALSE) will indicate that screenclear() was not
210 ! /* Trick: we want to avoid clearing the screen twice. screenclear() will
211 * set "screen_cleared" to TRUE. The special value MAYBE (which is still
212 * non-zero and thus not FALSE) will indicate that screenclear() was not
218 * At end of screen line and there is more to come: Display the line
219 ! * so far. If there is no more to display it is catched above.
222 #ifdef FEAT_RIGHTLEFT
226 * At end of screen line and there is more to come: Display the line
227 ! * so far. If there is no more to display it is caught above.
230 #ifdef FEAT_RIGHTLEFT
236 ! && ((*mb_off2cells)(LineOffset[screen_row]) == 2
237 || (*mb_off2cells)(LineOffset[screen_row - 1]
238 ! + (int)Columns - 2) == 2))
246 ! && ((*mb_off2cells)(LineOffset[screen_row],
247 ! LineOffset[screen_row] + screen_Columns)
249 || (*mb_off2cells)(LineOffset[screen_row - 1]
250 ! + (int)Columns - 2,
251 ! LineOffset[screen_row] + screen_Columns)
263 + unsigned max_off_from;
264 + unsigned max_off_to;
267 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT)
273 off_from = (unsigned)(current_ScreenLine - ScreenLines);
274 off_to = LineOffset[row] + coloff;
276 + max_off_from = off_from + screen_Columns;
277 + max_off_to = LineOffset[row] + screen_Columns;
280 #ifdef FEAT_RIGHTLEFT
286 if (has_mbyte && (col + 1 < endcol))
287 ! char_cells = (*mb_off2cells)(off_from);
294 if (has_mbyte && (col + 1 < endcol))
295 ! char_cells = (*mb_off2cells)(off_from, max_off_from);
301 * ScreenLinesUC[] is sufficient. */
304 ! && (*mb_off2cells)(off_to) > 1)
306 /* Writing a single-cell character over a double-cell
307 * character: need to redraw the next cell. */
309 * ScreenLinesUC[] is sufficient. */
312 ! && (*mb_off2cells)(off_to, max_off_to) > 1)
314 /* Writing a single-cell character over a double-cell
315 * character: need to redraw the next cell. */
319 else if (char_cells == 2
321 ! && (*mb_off2cells)(off_to) == 1
322 ! && (*mb_off2cells)(off_to + 1) > 1)
324 /* Writing the second half of a double-cell character over
325 * a double-cell character: need to redraw the second
328 else if (char_cells == 2
330 ! && (*mb_off2cells)(off_to, max_off_to) == 1
331 ! && (*mb_off2cells)(off_to + 1, max_off_to) > 1)
333 /* Writing the second half of a double-cell character over
334 * a double-cell character: need to redraw the second
337 * char over the left halve of an existing one. */
338 if (has_mbyte && col + char_cells == endcol
340 ! && (*mb_off2cells)(off_to) > 1)
342 ! && (*mb_off2cells)(off_to) == 1
343 ! && (*mb_off2cells)(off_to + 1) > 1)))
348 * char over the left halve of an existing one. */
349 if (has_mbyte && col + char_cells == endcol
351 ! && (*mb_off2cells)(off_to, max_off_to) > 1)
353 ! && (*mb_off2cells)(off_to, max_off_to) == 1
354 ! && (*mb_off2cells)(off_to + 1, max_off_to) > 1)))
360 /* find previous character by counting from first
361 * column and get its width. */
362 unsigned off = LineOffset[row];
366 ! prev_cells = (*mb_off2cells)(off);
371 /* find previous character by counting from first
372 * column and get its width. */
373 unsigned off = LineOffset[row];
374 + unsigned max_off = LineOffset[row] + screen_Columns;
378 ! prev_cells = (*mb_off2cells)(off, max_off);
384 static int skip_status_match_char __ARGS((expand_T *xp, char_u *s));
387 ! * Get the lenght of an item as it will be shown in the status line.
390 status_match_len(xp, s)
392 static int skip_status_match_char __ARGS((expand_T *xp, char_u *s));
395 ! * Get the length of an item as it will be shown in the status line.
398 status_match_len(xp, s)
404 ! int clen; /* lenght in screen cells */
412 ! int clen; /* length in screen cells */
431 off = LineOffset[row] + col;
433 + max_off = LineOffset[row] + screen_Columns;
435 while (col < screen_Columns
436 && (len < 0 || (int)(ptr - text) < len)
441 && (len < 0 ? ptr[mbyte_blen] == NUL
442 : ptr + mbyte_blen >= text + len)
443 ! && ((mbyte_cells == 1 && (*mb_off2cells)(off) > 1)
445 ! && (*mb_off2cells)(off) == 1
446 ! && (*mb_off2cells)(off + 1) > 1)))
447 clear_next_cell = TRUE;
449 /* Make sure we never leave a second byte of a double-byte behind,
450 * it confuses mb_off2cells(). */
452 ! && ((mbyte_cells == 1 && (*mb_off2cells)(off) > 1)
454 ! && (*mb_off2cells)(off) == 1
455 ! && (*mb_off2cells)(off + 1) > 1)))
456 ScreenLines[off + mbyte_blen] = 0;
458 ScreenLines[off] = c;
461 && (len < 0 ? ptr[mbyte_blen] == NUL
462 : ptr + mbyte_blen >= text + len)
463 ! && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1)
465 ! && (*mb_off2cells)(off, max_off) == 1
466 ! && (*mb_off2cells)(off + 1, max_off) > 1)))
467 clear_next_cell = TRUE;
469 /* Make sure we never leave a second byte of a double-byte behind,
470 * it confuses mb_off2cells(). */
472 ! && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1)
474 ! && (*mb_off2cells)(off, max_off) == 1
475 ! && (*mb_off2cells)(off + 1, max_off) > 1)))
476 ScreenLines[off + mbyte_blen] = 0;
478 ScreenLines[off] = c;
489 /* Can't use ScreenLines unless initialized */
490 if (ScreenLines == NULL)
493 for (r = row; r < row + height; ++r)
496 for (c = col; c < col + width; ++c)
499 ! if (enc_dbcs != 0 && dbcs_off2cells(off + c) > 1)
501 screen_char_2(off + c, r, c);
504 for (r = row; r < row + height; ++r)
508 + max_off = off + screen_Columns;
510 for (c = col; c < col + width; ++c)
513 ! if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1)
515 screen_char_2(off + c, r, c);
520 screen_char(off + c, r, c);
522 ! if (utf_off2cells(off + c) > 1)
528 screen_char(off + c, r, c);
530 ! if (utf_off2cells(off + c, max_off) > 1)
534 *** ../vim-7.1.092/src/version.c Thu Aug 30 12:50:00 2007
535 --- src/version.c Thu Aug 30 13:45:25 2007
539 { /* Add new patch number below this line */
545 There is a fine line between courage and foolishness.
546 Unfortunately, it's not a fence.
548 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
549 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
550 \\\ download, build and distribute -- http://www.A-A-P.org ///
551 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///