Mercurial > vim
comparison src/mbyte.c @ 13117:cfaa513efa3f v8.0.1433
patch 8.0.1433: illegal memory access after undo
commit https://github.com/vim/vim/commit/95dbcbea6d85a5b79d9617ab3863458fdf0217a0
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 27 21:01:34 2018 +0100
patch 8.0.1433: illegal memory access after undo
Problem: Illegal memory access after undo. (Dominique Pelle)
Solution: Avoid the column becomes negative. (Christian Brabandt,
closes #2533)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 27 Jan 2018 21:15:05 +0100 |
parents | 851393938fa3 |
children | ac42c4b11dbc |
comparison
equal
deleted
inserted
replaced
13116:4e4cb0764f0a | 13117:cfaa513efa3f |
---|---|
1782 | 1782 |
1783 /* | 1783 /* |
1784 * Convert a UTF-8 byte sequence to a wide character. | 1784 * Convert a UTF-8 byte sequence to a wide character. |
1785 * If the sequence is illegal or truncated by a NUL the first byte is | 1785 * If the sequence is illegal or truncated by a NUL the first byte is |
1786 * returned. | 1786 * returned. |
1787 * For an overlong sequence this may return zero. | |
1787 * Does not include composing characters, of course. | 1788 * Does not include composing characters, of course. |
1788 */ | 1789 */ |
1789 int | 1790 int |
1790 utf_ptr2char(char_u *p) | 1791 utf_ptr2char(char_u *p) |
1791 { | 1792 { |
4110 || lp->coladd > 1 | 4111 || lp->coladd > 1 |
4111 #endif | 4112 #endif |
4112 ) | 4113 ) |
4113 { | 4114 { |
4114 p = ml_get_buf(buf, lp->lnum, FALSE); | 4115 p = ml_get_buf(buf, lp->lnum, FALSE); |
4115 lp->col -= (*mb_head_off)(p, p + lp->col); | 4116 if (*p == NUL || (int)STRLEN(p) < lp->col) |
4117 lp->col = 0; | |
4118 else | |
4119 lp->col -= (*mb_head_off)(p, p + lp->col); | |
4116 #ifdef FEAT_VIRTUALEDIT | 4120 #ifdef FEAT_VIRTUALEDIT |
4117 /* Reset "coladd" when the cursor would be on the right half of a | 4121 /* Reset "coladd" when the cursor would be on the right half of a |
4118 * double-wide character. */ | 4122 * double-wide character. */ |
4119 if (lp->coladd == 1 | 4123 if (lp->coladd == 1 |
4120 && p[lp->col] != TAB | 4124 && p[lp->col] != TAB |