home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.2 / 7.2.200 < prev    next >
Encoding:
Internet Message Format  |  2009-06-15  |  10.1 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 7.2.200
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.2.200
  11. Problem:    Reading past end of string when navigating the menu bar or
  12.         resizing the window.
  13. Solution:   Add and use mb_ptr2len_len(). (partly by Dominique Pelle)
  14.         Also add mb_ptr2cells_len() to prevent more trouble.
  15. Files:        src/gui_gtk_x11.c, src/os_unix.c, src/globals.h, src/mbyte.c,
  16.         src/proto/mbyte.pro
  17.  
  18.  
  19. *** ../vim-7.2.199/src/gui_gtk_x11.c    2009-06-03 16:20:09.000000000 +0200
  20. --- src/gui_gtk_x11.c    2009-06-16 14:44:19.000000000 +0200
  21. ***************
  22. *** 6077,6088 ****
  23.   # ifdef FEAT_MBYTE
  24.           if (enc_utf8)
  25.           {
  26. !         c = utf_ptr2char(p);
  27.           if (c >= 0x10000)    /* show chars > 0xffff as ? */
  28.               c = 0xbf;
  29.           buf[textlen].byte1 = c >> 8;
  30.           buf[textlen].byte2 = c;
  31. !         p += utf_ptr2len(p);
  32.           width += utf_char2cells(c);
  33.           }
  34.           else
  35. --- 6135,6149 ----
  36.   # ifdef FEAT_MBYTE
  37.           if (enc_utf8)
  38.           {
  39. !         int pcc[MAX_MCO];
  40. !         /* TODO: use the composing characters */
  41. !         c = utfc_ptr2char_len(p, &pcc, len - (p - s));
  42.           if (c >= 0x10000)    /* show chars > 0xffff as ? */
  43.               c = 0xbf;
  44.           buf[textlen].byte1 = c >> 8;
  45.           buf[textlen].byte2 = c;
  46. !         p += utfc_ptr2len_len(p, len - (p - s));
  47.           width += utf_char2cells(c);
  48.           }
  49.           else
  50. ***************
  51. *** 6106,6113 ****
  52.       if (has_mbyte)
  53.       {
  54.           width = 0;
  55. !         for (p = s; p < s + len; p += (*mb_ptr2len)(p))
  56. !         width += (*mb_ptr2cells)(p);
  57.       }
  58.       else
  59.   # endif
  60. --- 6167,6174 ----
  61.       if (has_mbyte)
  62.       {
  63.           width = 0;
  64. !         for (p = s; p < s + len; p += (*mb_ptr2len_len)(p, len - (p - s)))
  65. !         width += (*mb_ptr2cells_len)(p, len - (p - s));
  66.       }
  67.       else
  68.   # endif
  69. *** ../vim-7.2.199/src/os_unix.c    2009-05-17 13:30:58.000000000 +0200
  70. --- src/os_unix.c    2009-06-03 12:35:59.000000000 +0200
  71. ***************
  72. *** 4305,4311 ****
  73.                   ta_buf[i] = '\n';
  74.   # ifdef FEAT_MBYTE
  75.                   if (has_mbyte)
  76. !                 i += (*mb_ptr2len)(ta_buf + i) - 1;
  77.   # endif
  78.               }
  79.   
  80. --- 4305,4312 ----
  81.                   ta_buf[i] = '\n';
  82.   # ifdef FEAT_MBYTE
  83.                   if (has_mbyte)
  84. !                 i += (*mb_ptr2len_len)(ta_buf + i,
  85. !                             ta_len + len - i) - 1;
  86.   # endif
  87.               }
  88.   
  89. *** ../vim-7.2.199/src/globals.h    2009-06-10 18:15:49.000000000 +0200
  90. --- src/globals.h    2009-06-12 21:10:30.000000000 +0200
  91. ***************
  92. *** 810,820 ****
  93. --- 815,828 ----
  94.    */
  95.   /* length of char in bytes, including following composing chars */
  96.   EXTERN int (*mb_ptr2len) __ARGS((char_u *p)) INIT(= latin_ptr2len);
  97. + /* idem, with limit on string length */
  98. + EXTERN int (*mb_ptr2len_len) __ARGS((char_u *p, int size)) INIT(= latin_ptr2len_len);
  99.   /* byte length of char */
  100.   EXTERN int (*mb_char2len) __ARGS((int c)) INIT(= latin_char2len);
  101.   /* convert char to bytes, return the length */
  102.   EXTERN int (*mb_char2bytes) __ARGS((int c, char_u *buf)) INIT(= latin_char2bytes);
  103.   EXTERN int (*mb_ptr2cells) __ARGS((char_u *p)) INIT(= latin_ptr2cells);
  104. + EXTERN int (*mb_ptr2cells_len) __ARGS((char_u *p, int size)) INIT(= latin_ptr2cells_len);
  105.   EXTERN int (*mb_char2cells) __ARGS((int c)) INIT(= latin_char2cells);
  106.   EXTERN int (*mb_off2cells) __ARGS((unsigned off, unsigned max_off)) INIT(= latin_off2cells);
  107.   EXTERN int (*mb_ptr2char) __ARGS((char_u *p)) INIT(= latin_ptr2char);
  108. *** ../vim-7.2.199/src/mbyte.c    2009-05-17 13:30:58.000000000 +0200
  109. --- src/mbyte.c    2009-06-16 15:01:30.000000000 +0200
  110. ***************
  111. *** 127,133 ****
  112. --- 127,136 ----
  113.   static int dbcs_char2len __ARGS((int c));
  114.   static int dbcs_char2bytes __ARGS((int c, char_u *buf));
  115.   static int dbcs_ptr2len __ARGS((char_u *p));
  116. + static int dbcs_ptr2len_len __ARGS((char_u *p, int size));
  117. + static int utf_ptr2cells_len __ARGS((char_u *p, int size));
  118.   static int dbcs_char2cells __ARGS((int c));
  119. + static int dbcs_ptr2cells_len __ARGS((char_u *p, int size));
  120.   static int dbcs_ptr2char __ARGS((char_u *p));
  121.   
  122.   /* Lookup table to quickly get the length in bytes of a UTF-8 character from
  123. ***************
  124. *** 606,614 ****
  125. --- 609,619 ----
  126.       if (enc_utf8)
  127.       {
  128.       mb_ptr2len = utfc_ptr2len;
  129. +     mb_ptr2len_len = utfc_ptr2len_len;
  130.       mb_char2len = utf_char2len;
  131.       mb_char2bytes = utf_char2bytes;
  132.       mb_ptr2cells = utf_ptr2cells;
  133. +     mb_ptr2cells_len = utf_ptr2cells_len;
  134.       mb_char2cells = utf_char2cells;
  135.       mb_off2cells = utf_off2cells;
  136.       mb_ptr2char = utf_ptr2char;
  137. ***************
  138. *** 617,625 ****
  139. --- 622,632 ----
  140.       else if (enc_dbcs != 0)
  141.       {
  142.       mb_ptr2len = dbcs_ptr2len;
  143. +     mb_ptr2len_len = dbcs_ptr2len_len;
  144.       mb_char2len = dbcs_char2len;
  145.       mb_char2bytes = dbcs_char2bytes;
  146.       mb_ptr2cells = dbcs_ptr2cells;
  147. +     mb_ptr2cells_len = dbcs_ptr2cells_len;
  148.       mb_char2cells = dbcs_char2cells;
  149.       mb_off2cells = dbcs_off2cells;
  150.       mb_ptr2char = dbcs_ptr2char;
  151. ***************
  152. *** 628,636 ****
  153. --- 635,645 ----
  154.       else
  155.       {
  156.       mb_ptr2len = latin_ptr2len;
  157. +     mb_ptr2len_len = latin_ptr2len_len;
  158.       mb_char2len = latin_char2len;
  159.       mb_char2bytes = latin_char2bytes;
  160.       mb_ptr2cells = latin_ptr2cells;
  161. +     mb_ptr2cells_len = latin_ptr2cells_len;
  162.       mb_char2cells = latin_char2cells;
  163.       mb_off2cells = latin_off2cells;
  164.       mb_ptr2char = latin_ptr2char;
  165. ***************
  166. *** 1069,1075 ****
  167.    * Get byte length of character at "*p" but stop at a NUL.
  168.    * For UTF-8 this includes following composing characters.
  169.    * Returns 0 when *p is NUL.
  170. -  *
  171.    */
  172.       int
  173.   latin_ptr2len(p)
  174. --- 1078,1083 ----
  175. ***************
  176. *** 1091,1096 ****
  177. --- 1099,1138 ----
  178.       return len;
  179.   }
  180.   
  181. + /*
  182. +  * mb_ptr2len_len() function pointer.
  183. +  * Like mb_ptr2len(), but limit to read "size" bytes.
  184. +  * Returns 0 for an empty string.
  185. +  * Returns 1 for an illegal char or an incomplete byte sequence.
  186. +  */
  187. +     int
  188. + latin_ptr2len_len(p, size)
  189. +     char_u    *p;
  190. +     int        size;
  191. + {
  192. +     if (size < 1 || *p == NUL)
  193. +     return 0;
  194. +     return 1;
  195. + }
  196. +     static int
  197. + dbcs_ptr2len_len(p, size)
  198. +     char_u    *p;
  199. +     int        size;
  200. + {
  201. +     int        len;
  202. +     if (size < 1 || *p == NUL)
  203. +     return 0;
  204. +     if (size == 1)
  205. +     return 1;
  206. +     /* Check that second byte is not missing. */
  207. +     len = MB_BYTE2LEN(*p);
  208. +     if (len == 2 && p[1] == NUL)
  209. +     len = 1;
  210. +     return len;
  211. + }
  212.   struct interval
  213.   {
  214.       unsigned short first;
  215. ***************
  216. *** 1287,1292 ****
  217. --- 1329,1383 ----
  218.   }
  219.   
  220.   /*
  221. +  * mb_ptr2cells_len() function pointer.
  222. +  * Like mb_ptr2cells(), but limit string length to "size".
  223. +  * For an empty string or truncated character returns 1.
  224. +  */
  225. +     int
  226. + latin_ptr2cells_len(p, size)
  227. +     char_u    *p UNUSED;
  228. +     int        size UNUSED;
  229. + {
  230. +     return 1;
  231. + }
  232. +     static int
  233. + utf_ptr2cells_len(p, size)
  234. +     char_u    *p;
  235. +     int        size;
  236. + {
  237. +     int        c;
  238. +     /* Need to convert to a wide character. */
  239. +     if (size > 0 && *p >= 0x80)
  240. +     {
  241. +     if (utf_ptr2len_len(p, size) < utf8len_tab[*p])
  242. +         return 1;
  243. +     c = utf_ptr2char(p);
  244. +     /* An illegal byte is displayed as <xx>. */
  245. +     if (utf_ptr2len(p) == 1 || c == NUL)
  246. +         return 4;
  247. +     /* If the char is ASCII it must be an overlong sequence. */
  248. +     if (c < 0x80)
  249. +         return char2cells(c);
  250. +     return utf_char2cells(c);
  251. +     }
  252. +     return 1;
  253. + }
  254. +     static int
  255. + dbcs_ptr2cells_len(p, size)
  256. +     char_u    *p;
  257. +     int        size;
  258. + {
  259. +     /* Number of cells is equal to number of bytes, except for euc-jp when
  260. +      * the first byte is 0x8e. */
  261. +     if (size <= 1 || (enc_dbcs == DBCS_JPNU && *p == 0x8e))
  262. +     return 1;
  263. +     return MB_BYTE2LEN(*p);
  264. + }
  265. + /*
  266.    * mb_char2cells() function pointer.
  267.    * Return the number of display cells character "c" occupies.
  268.    * Only takes care of multi-byte chars, not "^C" and such.
  269. ***************
  270. *** 1716,1721 ****
  271. --- 1807,1813 ----
  272.   /*
  273.    * Return the number of bytes the UTF-8 encoding of the character at "p[size]"
  274.    * takes.  This includes following composing characters.
  275. +  * Returns 0 for an empty string.
  276.    * Returns 1 for an illegal char or an incomplete byte sequence.
  277.    */
  278.       int
  279. ***************
  280. *** 1728,1734 ****
  281.       int        prevlen;
  282.   #endif
  283.   
  284. !     if (*p == NUL)
  285.       return 0;
  286.       if (p[0] < 0x80 && (size == 1 || p[1] < 0x80)) /* be quick for ASCII */
  287.       return 1;
  288. --- 1820,1826 ----
  289.       int        prevlen;
  290.   #endif
  291.   
  292. !     if (size < 1 || *p == NUL)
  293.       return 0;
  294.       if (p[0] < 0x80 && (size == 1 || p[1] < 0x80)) /* be quick for ASCII */
  295.       return 1;
  296. *** ../vim-7.2.199/src/proto/mbyte.pro    2008-07-13 19:34:19.000000000 +0200
  297. --- src/proto/mbyte.pro    2009-06-16 14:58:39.000000000 +0200
  298. ***************
  299. *** 7,16 ****
  300. --- 7,18 ----
  301.   int latin_char2len __ARGS((int c));
  302.   int latin_char2bytes __ARGS((int c, char_u *buf));
  303.   int latin_ptr2len __ARGS((char_u *p));
  304. + int latin_ptr2len_len __ARGS((char_u *p, int size));
  305.   int utf_char2cells __ARGS((int c));
  306.   int latin_ptr2cells __ARGS((char_u *p));
  307.   int utf_ptr2cells __ARGS((char_u *p));
  308.   int dbcs_ptr2cells __ARGS((char_u *p));
  309. + int latin_ptr2cells_len __ARGS((char_u *p, int size));
  310.   int latin_char2cells __ARGS((int c));
  311.   int latin_off2cells __ARGS((unsigned off, unsigned max_off));
  312.   int dbcs_off2cells __ARGS((unsigned off, unsigned max_off));
  313. ***************
  314. *** 85,90 ****
  315. --- 87,93 ----
  316.   int preedit_get_status __ARGS((void));
  317.   int im_is_preediting __ARGS((void));
  318.   int convert_setup __ARGS((vimconv_T *vcp, char_u *from, char_u *to));
  319. + int convert_setup_ext __ARGS((vimconv_T *vcp, char_u *from, int from_unicode_is_utf8, char_u *to, int to_unicode_is_utf8));
  320.   int convert_input __ARGS((char_u *ptr, int len, int maxlen));
  321.   int convert_input_safe __ARGS((char_u *ptr, int len, int maxlen, char_u **restp, int *restlenp));
  322.   char_u *string_convert __ARGS((vimconv_T *vcp, char_u *ptr, int *lenp));
  323. *** ../vim-7.2.199/src/version.c    2009-06-16 14:31:56.000000000 +0200
  324. --- src/version.c    2009-06-16 14:37:38.000000000 +0200
  325. ***************
  326. *** 678,679 ****
  327. --- 678,681 ----
  328.   {   /* Add new patch number below this line */
  329. + /**/
  330. +     200,
  331.   /**/
  332.  
  333. -- 
  334. How To Keep A Healthy Level Of Insanity:
  335. 12. Sing along at the opera.
  336.  
  337.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  338. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  339. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  340.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  341.