diff options
author | Bram Moolenaar <Bram@vim.org> | 2008-06-29 14:16:06 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2008-06-29 14:16:06 +0000 |
commit | 89bf0927af4c8c3bbd2b9ae4558e0a581380d83f (patch) | |
tree | 15c82ecbbed213d7135add0c437c39a33e8b3805 /src/mbyte.c | |
parent | 0d1498ea69faad513f7e55c74c220990f9d89996 (diff) | |
download | vim-git-89bf0927af4c8c3bbd2b9ae4558e0a581380d83f.tar.gz |
updated for version 7.2a-010v7.2a.010
Diffstat (limited to 'src/mbyte.c')
-rw-r--r-- | src/mbyte.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/mbyte.c b/src/mbyte.c index 4e9059366..d6edf201e 100644 --- a/src/mbyte.c +++ b/src/mbyte.c @@ -1387,7 +1387,7 @@ utf_ptr2char(p) return p[0]; len = utf8len_tab[p[0]]; - if ((p[1] & 0xc0) == 0x80) + if (len > 1 && (p[1] & 0xc0) == 0x80) { if (len == 2) return ((p[0] & 0x1f) << 6) + (p[1] & 0x3f); @@ -1753,14 +1753,27 @@ utfc_ptr2len_len(p, size) #endif while (len < size) { - if (p[len] < 0x80 || !UTF_COMPOSINGLIKE(p + prevlen, p + len)) + int len_next_char; + + if (p[len] < 0x80) + break; + + /* + * Next character length should not go beyond size to ensure that + * UTF_COMPOSINGLIKE(...) does not read beyond size. + */ + len_next_char = utf_ptr2len_len(p + len, size - len); + if (len_next_char > size - len) + break; + + if (!UTF_COMPOSINGLIKE(p + prevlen, p + len)) break; /* Skip over composing char */ #ifdef FEAT_ARABIC prevlen = len; #endif - len += utf_ptr2len_len(p + len, size - len); + len += len_next_char; } return len; } |