Mercurial > vim
diff src/misc2.c @ 6765:ec46a5ca1b51 v7.4.704
patch 7.4.704
Problem: Searching for a character matches an illegal byte and causes
invalid memory access. (Dominique Pelle)
Solution: Do not match an invalid byte when search for a character in a
string. Fix equivalence classes using negative numbers, which
result in illegal bytes.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Tue, 21 Apr 2015 14:02:35 +0200 |
parents | 8bee881c3ca5 |
children | 58d9f967ae1a |
line wrap: on
line diff
--- a/src/misc2.c +++ b/src/misc2.c @@ -1885,9 +1885,12 @@ vim_strchr(string, c) { while (*p != NUL) { - if (utf_ptr2char(p) == c) + int l = (*mb_ptr2len)(p); + + /* Avoid matching an illegal byte here. */ + if (utf_ptr2char(p) == c && l > 1) return p; - p += (*mb_ptr2len)(p); + p += l; } return NULL; }