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.080 < prev    next >
Encoding:
Internet Message Format  |  2009-01-12  |  9.7 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 7.2.080
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=ISO-8859-1
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.2.080
  11. Problem:    When typing a composing character just after starting completion
  12.         may access memory before its allocation point. (Dominique Pelle)
  13. Solution:   Don't delete before the completion start column.  Add extra checks
  14.         for the offset not being negative.
  15. Files:        src/edit.c
  16.  
  17.  
  18. *** ../vim-7.2.079/src/edit.c    Wed Aug  6 18:56:55 2008
  19. --- src/edit.c    Tue Jan 13 12:05:57 2009
  20. ***************
  21. *** 147,152 ****
  22. --- 147,153 ----
  23.   static int  ins_compl_bs __ARGS((void));
  24.   static void ins_compl_new_leader __ARGS((void));
  25.   static void ins_compl_addleader __ARGS((int c));
  26. + static int ins_compl_len __ARGS((void));
  27.   static void ins_compl_restart __ARGS((void));
  28.   static void ins_compl_set_original_text __ARGS((char_u *str));
  29.   static void ins_compl_addfrommatch __ARGS((void));
  30. ***************
  31. *** 197,203 ****
  32.   static void mb_replace_pop_ins __ARGS((int cc));
  33.   #endif
  34.   static void replace_flush __ARGS((void));
  35. ! static void replace_do_bs __ARGS((void));
  36.   #ifdef FEAT_CINDENT
  37.   static int cindent_on __ARGS((void));
  38.   #endif
  39. --- 198,205 ----
  40.   static void mb_replace_pop_ins __ARGS((int cc));
  41.   #endif
  42.   static void replace_flush __ARGS((void));
  43. ! static void replace_do_bs __ARGS((int limit_col));
  44. ! static int del_char_after_col __ARGS((int limit_col));
  45.   #ifdef FEAT_CINDENT
  46.   static int cindent_on __ARGS((void));
  47.   #endif
  48. ***************
  49. *** 1933,1938 ****
  50. --- 1935,1942 ----
  51.   /*
  52.    * Backspace the cursor until the given column.  Handles REPLACE and VREPLACE
  53.    * modes correctly.  May also be used when not in insert mode at all.
  54. +  * Will attempt not to go before "col" even when there is a composing
  55. +  * character.
  56.    */
  57.       void
  58.   backspace_until_column(col)
  59. ***************
  60. *** 1942,1954 ****
  61.       {
  62.       curwin->w_cursor.col--;
  63.       if (State & REPLACE_FLAG)
  64. !         replace_do_bs();
  65. !     else
  66. !         (void)del_char(FALSE);
  67.       }
  68.   }
  69.   #endif
  70.   
  71.   #if defined(FEAT_INS_EXPAND) || defined(PROTO)
  72.   /*
  73.    * CTRL-X pressed in Insert mode.
  74. --- 1946,1994 ----
  75.       {
  76.       curwin->w_cursor.col--;
  77.       if (State & REPLACE_FLAG)
  78. !         replace_do_bs(col);
  79. !     else if (!del_char_after_col(col))
  80. !         break;
  81.       }
  82.   }
  83.   #endif
  84.   
  85. + /*
  86. +  * Like del_char(), but make sure not to go before column "limit_col".
  87. +  * Only matters when there are composing characters.
  88. +  * Return TRUE when something was deleted.
  89. +  */
  90. +    static int
  91. + del_char_after_col(limit_col)
  92. +     int limit_col;
  93. + {
  94. + #ifdef FEAT_MBYTE
  95. +     if (enc_utf8 && limit_col >= 0)
  96. +     {
  97. +     int ecol = curwin->w_cursor.col + 1;
  98. +     /* Make sure the cursor is at the start of a character, but
  99. +      * skip forward again when going too far back because of a
  100. +      * composing character. */
  101. +     mb_adjust_cursor();
  102. +     while (curwin->w_cursor.col < limit_col)
  103. +     {
  104. +         int l = utf_ptr2len(ml_get_cursor());
  105. +         if (l == 0)  /* end of line */
  106. +         break;
  107. +         curwin->w_cursor.col += l;
  108. +     }
  109. +     if (*ml_get_cursor() == NUL || curwin->w_cursor.col == ecol)
  110. +         return FALSE;
  111. +     del_bytes((long)(ecol - curwin->w_cursor.col), FALSE, TRUE);
  112. +     }
  113. +     else
  114. + #endif
  115. +     (void)del_char(FALSE);
  116. +     return TRUE;
  117. + }
  118.   #if defined(FEAT_INS_EXPAND) || defined(PROTO)
  119.   /*
  120.    * CTRL-X pressed in Insert mode.
  121. ***************
  122. *** 2418,2424 ****
  123.       {
  124.           had_match = (curwin->w_cursor.col > compl_col);
  125.           ins_compl_delete();
  126. !         ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
  127.           ins_redraw(FALSE);
  128.   
  129.           /* When the match isn't there (to avoid matching itself) remove it
  130. --- 2458,2464 ----
  131.       {
  132.           had_match = (curwin->w_cursor.col > compl_col);
  133.           ins_compl_delete();
  134. !         ins_bytes(compl_leader + ins_compl_len());
  135.           ins_redraw(FALSE);
  136.   
  137.           /* When the match isn't there (to avoid matching itself) remove it
  138. ***************
  139. *** 2470,2476 ****
  140.           *p = NUL;
  141.           had_match = (curwin->w_cursor.col > compl_col);
  142.           ins_compl_delete();
  143. !         ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
  144.           ins_redraw(FALSE);
  145.   
  146.           /* When the match isn't there (to avoid matching itself) remove it
  147. --- 2510,2516 ----
  148.           *p = NUL;
  149.           had_match = (curwin->w_cursor.col > compl_col);
  150.           ins_compl_delete();
  151. !         ins_bytes(compl_leader + ins_compl_len());
  152.           ins_redraw(FALSE);
  153.   
  154.           /* When the match isn't there (to avoid matching itself) remove it
  155. ***************
  156. *** 3209,3215 ****
  157.   {
  158.       ins_compl_del_pum();
  159.       ins_compl_delete();
  160. !     ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
  161.       compl_used_match = FALSE;
  162.   
  163.       if (compl_started)
  164. --- 3249,3255 ----
  165.   {
  166.       ins_compl_del_pum();
  167.       ins_compl_delete();
  168. !     ins_bytes(compl_leader + ins_compl_len());
  169.       compl_used_match = FALSE;
  170.   
  171.       if (compl_started)
  172. ***************
  173. *** 3264,3269 ****
  174. --- 3304,3323 ----
  175.   }
  176.   
  177.   /*
  178. +  * Return the length of the completion, from the completion start column to
  179. +  * the cursor column.  Making sure it never goes below zero.
  180. +  */
  181. +     static int
  182. + ins_compl_len()
  183. + {
  184. +     int off = curwin->w_cursor.col - compl_col;
  185. +     if (off < 0)
  186. +     return 0;
  187. +     return off;
  188. + }
  189. + /*
  190.    * Append one character to the match leader.  May reduce the number of
  191.    * matches.
  192.    */
  193. ***************
  194. *** 3621,3630 ****
  195.           {
  196.           ins_compl_delete();
  197.           if (compl_leader != NULL)
  198. !             ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
  199.           else if (compl_first_match != NULL)
  200. !             ins_bytes(compl_orig_text
  201. !                       + curwin->w_cursor.col - compl_col);
  202.           retval = TRUE;
  203.           }
  204.   
  205. --- 3675,3683 ----
  206.           {
  207.           ins_compl_delete();
  208.           if (compl_leader != NULL)
  209. !             ins_bytes(compl_leader + ins_compl_len());
  210.           else if (compl_first_match != NULL)
  211. !             ins_bytes(compl_orig_text + ins_compl_len());
  212.           retval = TRUE;
  213.           }
  214.   
  215. ***************
  216. *** 4256,4262 ****
  217.       static void
  218.   ins_compl_insert()
  219.   {
  220. !     ins_bytes(compl_shown_match->cp_str + curwin->w_cursor.col - compl_col);
  221.       if (compl_shown_match->cp_flags & ORIGINAL_TEXT)
  222.       compl_used_match = FALSE;
  223.       else
  224. --- 4309,4315 ----
  225.       static void
  226.   ins_compl_insert()
  227.   {
  228. !     ins_bytes(compl_shown_match->cp_str + ins_compl_len());
  229.       if (compl_shown_match->cp_flags & ORIGINAL_TEXT)
  230.       compl_used_match = FALSE;
  231.       else
  232. ***************
  233. *** 4425,4431 ****
  234.       if (!compl_get_longest || compl_used_match)
  235.           ins_compl_insert();
  236.       else
  237. !         ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
  238.       }
  239.       else
  240.       compl_used_match = FALSE;
  241. --- 4478,4484 ----
  242.       if (!compl_get_longest || compl_used_match)
  243.           ins_compl_insert();
  244.       else
  245. !         ins_bytes(compl_leader + ins_compl_len());
  246.       }
  247.       else
  248.       compl_used_match = FALSE;
  249. ***************
  250. *** 7123,7131 ****
  251.    * cc == 0: character was inserted, delete it
  252.    * cc > 0: character was replaced, put cc (first byte of original char) back
  253.    * and check for more characters to be put back
  254.    */
  255.       static void
  256. ! replace_do_bs()
  257.   {
  258.       int        cc;
  259.   #ifdef FEAT_VREPLACE
  260. --- 7176,7187 ----
  261.    * cc == 0: character was inserted, delete it
  262.    * cc > 0: character was replaced, put cc (first byte of original char) back
  263.    * and check for more characters to be put back
  264. +  * When "limit_col" is >= 0, don't delete before this column.  Matters when
  265. +  * using composing characters, use del_char_after_col() instead of del_char().
  266.    */
  267.       static void
  268. ! replace_do_bs(limit_col)
  269. !     int        limit_col;
  270.   {
  271.       int        cc;
  272.   #ifdef FEAT_VREPLACE
  273. ***************
  274. *** 7153,7159 ****
  275.   #ifdef FEAT_MBYTE
  276.       if (has_mbyte)
  277.       {
  278. !         del_char(FALSE);
  279.   # ifdef FEAT_VREPLACE
  280.           if (State & VREPLACE_FLAG)
  281.           orig_len = (int)STRLEN(ml_get_cursor());
  282. --- 7209,7215 ----
  283.   #ifdef FEAT_MBYTE
  284.       if (has_mbyte)
  285.       {
  286. !         (void)del_char_after_col(limit_col);
  287.   # ifdef FEAT_VREPLACE
  288.           if (State & VREPLACE_FLAG)
  289.           orig_len = (int)STRLEN(ml_get_cursor());
  290. ***************
  291. *** 7203,7209 ****
  292.       changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
  293.       }
  294.       else if (cc == 0)
  295. !     (void)del_char(FALSE);
  296.   }
  297.   
  298.   #ifdef FEAT_CINDENT
  299. --- 7259,7265 ----
  300.       changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
  301.       }
  302.       else if (cc == 0)
  303. !     (void)del_char_after_col(limit_col);
  304.   }
  305.   
  306.   #ifdef FEAT_CINDENT
  307. ***************
  308. *** 8239,8245 ****
  309.        * Replace mode */
  310.       if (curwin->w_cursor.lnum != Insstart.lnum
  311.           || curwin->w_cursor.col >= Insstart.col)
  312. !         replace_do_bs();
  313.       }
  314.       else
  315.       (void)del_char(FALSE);
  316. --- 8295,8301 ----
  317.        * Replace mode */
  318.       if (curwin->w_cursor.lnum != Insstart.lnum
  319.           || curwin->w_cursor.col >= Insstart.col)
  320. !         replace_do_bs(-1);
  321.       }
  322.       else
  323.       (void)del_char(FALSE);
  324. ***************
  325. *** 8556,8562 ****
  326.           break;
  327.           }
  328.           if (State & REPLACE_FLAG)
  329. !         replace_do_bs();
  330.           else
  331.           {
  332.   #ifdef FEAT_MBYTE
  333. --- 8612,8618 ----
  334.           break;
  335.           }
  336.           if (State & REPLACE_FLAG)
  337. !         replace_do_bs(-1);
  338.           else
  339.           {
  340.   #ifdef FEAT_MBYTE
  341. *** ../vim-7.2.079/src/version.c    Tue Jan  6 16:13:42 2009
  342. --- src/version.c    Tue Jan 13 12:25:29 2009
  343. ***************
  344. *** 678,679 ****
  345. --- 678,681 ----
  346.   {   /* Add new patch number below this line */
  347. + /**/
  348. +     80,
  349.   /**/
  350.  
  351. -- 
  352. At some point in the project somebody will start whining about the need to
  353. determine the project "requirements".  This involves interviewing people who
  354. don't know what they want but, curiously, know exactly when they need it.
  355.                 (Scott Adams - The Dilbert principle)
  356.  
  357.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  358. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  359. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  360.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  361.