To: vim-dev@vim.org Subject: Patch 6.0.019 Fcc: outbox From: Bram Moolenaar MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.0.019 Problem: Converting a string with multi-byte characters to a printable string, e.g., with strtrans(), may cause a crash. (Tomas Zellerin) Solution: Correctly compute the length of the result in transstr(). Files: src/charset.c *** ../vim60.18/src/charset.c Wed Sep 19 17:28:08 2001 --- src/charset.c Mon Oct 22 12:43:03 2001 *************** *** 327,351 **** char_u *s; { char_u *res; #ifdef FEAT_MBYTE ! int l; #endif ! res = alloc((unsigned)(vim_strsize(s) + 1)); if (res != NULL) { *res = NUL; ! while (*s != NUL) { #ifdef FEAT_MBYTE ! if (has_mbyte && (l = (*mb_ptr2len_check)(s)) > 1) { ! STRNCAT(res, s, l); ! s += l; } else #endif ! STRCAT(res, transchar(*s++)); } } return res; --- 327,374 ---- char_u *s; { char_u *res; + char_u *p; #ifdef FEAT_MBYTE ! int l, len; #endif ! #ifdef FEAT_MBYTE ! if (has_mbyte) ! { ! /* Compute the length of the result, taking into account that ! * multi-byte characters are copied unchanged. */ ! len = 0; ! p = s; ! while (*p != NUL) ! { ! if ((l = (*mb_ptr2len_check)(p)) > 1) ! { ! len += l; ! p += l; ! } ! else ! len += byte2cells(*p++); ! } ! res = alloc((unsigned)(len + 1)); ! } ! else ! #endif ! res = alloc((unsigned)(vim_strsize(s) + 1)); if (res != NULL) { *res = NUL; ! p = s; ! while (*p != NUL) { #ifdef FEAT_MBYTE ! if (has_mbyte && (l = (*mb_ptr2len_check)(p)) > 1) { ! STRNCAT(res, p, l); ! p += l; } else #endif ! STRCAT(res, transchar(*p++)); } } return res; *** ../vim60.18/src/version.c Mon Oct 22 12:47:09 2001 --- src/version.c Mon Oct 22 12:46:56 2001 *************** *** 608,609 **** --- 608,611 ---- { /* Add new patch number below this line */ + /**/ + 19, /**/ -- "Hit any key to continue" is very confusing when you have two keyboards. /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net \\\ ((( Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim ))) \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///