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 / 6.2.187 < prev    next >
Encoding:
Internet Message Format  |  2004-01-17  |  14.4 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 6.2.187
  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 6.2.187
  11. Problem:    Using Insure++ reveals a number of bugs.  (Dominuque Pelle)
  12. Solution:   Initialize variables where needed.  Free allocated memory to avoid
  13.         leaks.  Fix comparing tags to avoid reading past allocated memory.
  14. Files:        src/buffer.c, src/diff.c, src/fileio.c, src/mark.c, src/misc1.c,
  15.         src/misc2.c, src/ops.c, src/option.c, src/tag.c, src/ui.c
  16.  
  17.  
  18. *** ../vim-6.2.186/src/buffer.c    Sun Nov  9 20:35:08 2003
  19. --- src/buffer.c    Thu Jan 15 22:10:02 2004
  20. ***************
  21. *** 4085,4090 ****
  22. --- 4085,4091 ----
  23.   #ifdef FEAT_AUTOCMD
  24.       --autocmd_no_leave;
  25.   #endif
  26. +     vim_free(opened);
  27.   }
  28.   
  29.   # if defined(FEAT_LISTCMDS) || defined(PROTO)
  30. *** ../vim-6.2.186/src/diff.c    Sun Oct 27 19:28:04 2002
  31. --- src/diff.c    Fri Jan 16 11:52:11 2004
  32. ***************
  33. *** 952,958 ****
  34.       curwin = wp;
  35.       curbuf = curwin->w_buffer;
  36.       set_string_option_direct((char_u *)"fdm", -1, (char_u *)"diff",
  37. !                                    OPT_LOCAL);
  38.       curwin = old_curwin;
  39.       curbuf = curwin->w_buffer;
  40.       wp->w_p_fdc = 2;
  41. --- 952,958 ----
  42.       curwin = wp;
  43.       curbuf = curwin->w_buffer;
  44.       set_string_option_direct((char_u *)"fdm", -1, (char_u *)"diff",
  45. !                               OPT_LOCAL|OPT_FREE);
  46.       curwin = old_curwin;
  47.       curbuf = curwin->w_buffer;
  48.       wp->w_p_fdc = 2;
  49. *** ../vim-6.2.186/src/fileio.c    Fri Jan  9 14:33:14 2004
  50. --- src/fileio.c    Thu Jan 15 22:07:40 2004
  51. ***************
  52. *** 3233,3239 ****
  53.   
  54.   #if defined(UNIX) && !defined(ARCHIE)
  55.       /* When using ":w!" and the file was read-only: make it writable */
  56. !     if (forceit && st_old.st_uid == getuid() && perm >= 0 && !(perm & 0200)
  57.                        && vim_strchr(p_cpo, CPO_FWRITE) == NULL)
  58.       {
  59.       perm |= 0200;
  60. --- 3262,3268 ----
  61.   
  62.   #if defined(UNIX) && !defined(ARCHIE)
  63.       /* When using ":w!" and the file was read-only: make it writable */
  64. !     if (forceit && perm >= 0 && !(perm & 0200) && st_old.st_uid == getuid()
  65.                        && vim_strchr(p_cpo, CPO_FWRITE) == NULL)
  66.       {
  67.       perm |= 0200;
  68. *** ../vim-6.2.186/src/mark.c    Sat Sep 27 19:36:47 2003
  69. --- src/mark.c    Fri Jan 16 11:56:14 2004
  70. ***************
  71. *** 1140,1151 ****
  72.       name = buflist_nr2name(fm->fmark.fnum, TRUE, FALSE);
  73.       else
  74.       name = fm->fname;        /* use name from .viminfo */
  75. !     if (name == NULL || *name == NUL)
  76. !     return;
  77. !     fprintf(fp, "%c%c  %ld  %ld  ", c1, c2, (long)fm->fmark.mark.lnum,
  78.                               (long)fm->fmark.mark.col);
  79. !     viminfo_writestring(fp, name);
  80.       if (fm->fmark.fnum != 0)
  81.       vim_free(name);
  82.   }
  83. --- 1145,1157 ----
  84.       name = buflist_nr2name(fm->fmark.fnum, TRUE, FALSE);
  85.       else
  86.       name = fm->fname;        /* use name from .viminfo */
  87. !     if (name != NULL && *name != NUL)
  88. !     {
  89. !     fprintf(fp, "%c%c  %ld  %ld  ", c1, c2, (long)fm->fmark.mark.lnum,
  90.                               (long)fm->fmark.mark.col);
  91. !     viminfo_writestring(fp, name);
  92. !     }
  93.       if (fm->fmark.fnum != 0)
  94.       vim_free(name);
  95.   }
  96. *** ../vim-6.2.186/src/misc1.c    Sun Jan 18 20:15:02 2004
  97. --- src/misc1.c    Sun Jan 18 16:07:34 2004
  98. ***************
  99. *** 1368,1373 ****
  100. --- 1368,1374 ----
  101.       curwin->w_cursor.coladd = 0;
  102.   #endif
  103.       ins_bytes(p_extra);    /* will call changed_bytes() */
  104. +     vim_free(p_extra);
  105.       next_line = NULL;
  106.       }
  107.   #endif
  108. *** ../vim-6.2.186/src/misc2.c    Sat Sep 27 19:36:47 2003
  109. --- src/misc2.c    Fri Jan 16 15:19:08 2004
  110. ***************
  111. *** 2129,2135 ****
  112.       char_u    *dst;
  113.       int        keycode; /* prefer key code, e.g. K_DEL instead of DEL */
  114.   {
  115. !     int        modifiers;
  116.       int        key;
  117.       int        dlen = 0;
  118.   
  119. --- 2129,2135 ----
  120.       char_u    *dst;
  121.       int        keycode; /* prefer key code, e.g. K_DEL instead of DEL */
  122.   {
  123. !     int        modifiers = 0;
  124.       int        key;
  125.       int        dlen = 0;
  126.   
  127. ***************
  128. *** 4368,4373 ****
  129. --- 4368,4376 ----
  130.       while (vl != NULL)
  131.       {
  132.       vp = vl->ffv_next;
  133. + #ifdef FEAT_PATH_EXTRA
  134. +     vim_free(vl->ffv_wc_path);
  135. + #endif
  136.       vim_free(vl);
  137.       vl = vp;
  138.       }
  139. *** ../vim-6.2.186/src/ops.c    Sun Oct 12 16:56:43 2003
  140. --- src/ops.c    Thu Jan 15 22:30:37 2004
  141. ***************
  142. *** 5610,5619 ****
  143.       if (s == NULL)
  144.           break;
  145.       if (extra)
  146. -     {
  147.           mch_memmove(s, y_ptr->y_array[lnum], (size_t)extra);
  148.           vim_free(y_ptr->y_array[lnum]);
  149. -     }
  150.       if (i)
  151.           mch_memmove(s + extra, str + start, (size_t)i);
  152.       extra += i;
  153. --- 5610,5618 ----
  154.       if (s == NULL)
  155.           break;
  156.       if (extra)
  157.           mch_memmove(s, y_ptr->y_array[lnum], (size_t)extra);
  158. +     if (append)
  159.           vim_free(y_ptr->y_array[lnum]);
  160.       if (i)
  161.           mch_memmove(s + extra, str + start, (size_t)i);
  162.       extra += i;
  163. *** ../vim-6.2.186/src/option.c    Sun Oct 26 20:19:23 2003
  164. --- src/option.c    Thu Jan 15 22:03:06 2004
  165. ***************
  166. *** 7008,7013 ****
  167. --- 7008,7014 ----
  168.       else
  169.       {
  170.       --arg;                /* put arg at the '<' */
  171. +     modifiers = 0;
  172.       key = find_special_key(&arg, &modifiers, TRUE);
  173.       if (modifiers)            /* can't handle modifiers here */
  174.           key = 0;
  175. *** ../vim-6.2.186/src/tag.c    Mon Dec 29 19:48:35 2003
  176. --- src/tag.c    Sun Jan 18 13:05:42 2004
  177. ***************
  178. *** 1066,1071 ****
  179. --- 1066,1076 ----
  180.       int        is_etag;        /* current file is emaces style */
  181.   #endif
  182.   
  183. +     struct match_found
  184. +     {
  185. +     int    len;        /* nr of chars of match[] to be compared */
  186. +     char_u    match[1];    /* actually longer */
  187. +     } *mfp, *mfp2;
  188.       garray_T    ga_match[MT_COUNT];
  189.       int        match_count = 0;        /* number of matches found */
  190.       char_u    **matches;
  191. ***************
  192. *** 1110,1116 ****
  193.       ebuf = alloc(LSIZE);
  194.   #endif
  195.       for (mtt = 0; mtt < MT_COUNT; ++mtt)
  196. !     ga_init2(&ga_match[mtt], (int)sizeof(char_u *), 100);
  197.   
  198.       /* check for out of memory situation */
  199.       if (lbuf == NULL || tag_fname == NULL
  200. --- 1115,1121 ----
  201.       ebuf = alloc(LSIZE);
  202.   #endif
  203.       for (mtt = 0; mtt < MT_COUNT; ++mtt)
  204. !     ga_init2(&ga_match[mtt], (int)sizeof(struct match_found *), 100);
  205.   
  206.       /* check for out of memory situation */
  207.       if (lbuf == NULL || tag_fname == NULL
  208. ***************
  209. *** 1726,1738 ****
  210.           cc = *tagp.tagname_end;
  211.           *tagp.tagname_end = NUL;
  212.           match = vim_regexec(®match, tagp.tagname, (colnr_T)0);
  213. !         matchoff = (int)(regmatch.startp[0] - tagp.tagname);
  214. !         if (match && regmatch.rm_ic)
  215.           {
  216. !             regmatch.rm_ic = FALSE;
  217. !             match_no_ic = vim_regexec(®match, tagp.tagname,
  218.                                     (colnr_T)0);
  219. !             regmatch.rm_ic = TRUE;
  220.           }
  221.           *tagp.tagname_end = cc;
  222.           match_re = TRUE;
  223. --- 1731,1746 ----
  224.           cc = *tagp.tagname_end;
  225.           *tagp.tagname_end = NUL;
  226.           match = vim_regexec(®match, tagp.tagname, (colnr_T)0);
  227. !         if (match)
  228.           {
  229. !             matchoff = (int)(regmatch.startp[0] - tagp.tagname);
  230. !             if (regmatch.rm_ic)
  231. !             {
  232. !             regmatch.rm_ic = FALSE;
  233. !             match_no_ic = vim_regexec(®match, tagp.tagname,
  234.                                     (colnr_T)0);
  235. !             regmatch.rm_ic = TRUE;
  236. !             }
  237.           }
  238.           *tagp.tagname_end = cc;
  239.           match_re = TRUE;
  240. ***************
  241. *** 1793,1798 ****
  242. --- 1801,1811 ----
  243.               mtt += MT_RE_OFF;
  244.           }
  245.   
  246. +         /*
  247. +          * Add the found match in ga_match[mtt], avoiding duplicates.
  248. +          * Store the info we need later, which depends on the kind of
  249. +          * tags we are dealing with.
  250. +          */
  251.           if (ga_grow(&ga_match[mtt], 1) == OK)
  252.           {
  253.               if (help_only)
  254. ***************
  255. *** 1803,1846 ****
  256.                */
  257.               *tagp.tagname_end = NUL;
  258.               len = (int)(tagp.tagname_end - tagp.tagname);
  259. !             p = vim_strnsave(tagp.tagname, len + 10);
  260. !             if (p != NULL)
  261.                   sprintf((char *)p + len + 1, "%06d",
  262.                       help_heuristic(tagp.tagname,
  263.                       match_re ? matchoff : 0, !match_no_ic));
  264.               *tagp.tagname_end = TAB;
  265. -             ++len;    /* compare one more char */
  266.               }
  267.               else if (name_only)
  268.               {
  269. -             p = NULL;
  270. -             len = 0;
  271.               if (get_it_again)
  272.               {
  273.                   char_u *temp_end = tagp.command;
  274.   
  275. !                 if ((*temp_end) == '/')
  276. !                 while ( *temp_end && (*temp_end != '\r')
  277. !                     && (*temp_end != '\n')
  278. !                     && (*temp_end != '$'))
  279.                       temp_end++;
  280.   
  281. !                 if ((tagp.command + 2) < temp_end)
  282.                   {
  283.                   len = (int)(temp_end - tagp.command - 2);
  284. !                 p = vim_strnsave(tagp.command + 2, len);
  285.                   }
  286.                   get_it_again = FALSE;
  287.               }
  288.               else
  289.               {
  290.                   len = (int)(tagp.tagname_end - tagp.tagname);
  291. !                 p = vim_strnsave(tagp.tagname, len);
  292. !                 /* if wanted, re-read line to get long form too*/
  293.                   if (State & INSERT)
  294.                   get_it_again = p_sft;
  295.               }
  296. -             ++len;    /* compare one more char */
  297.               }
  298.               else
  299.               {
  300. --- 1816,1880 ----
  301.                */
  302.               *tagp.tagname_end = NUL;
  303.               len = (int)(tagp.tagname_end - tagp.tagname);
  304. !             mfp = (struct match_found *)
  305. !                  alloc(sizeof(struct match_found) + len + 10);
  306. !             if (mfp != NULL)
  307. !             {
  308. !                 mfp->len = len + 1;    /* also compare the NUL */
  309. !                 p = mfp->match;
  310. !                 STRCPY(p, tagp.tagname);
  311.                   sprintf((char *)p + len + 1, "%06d",
  312.                       help_heuristic(tagp.tagname,
  313.                       match_re ? matchoff : 0, !match_no_ic));
  314. +             }
  315.               *tagp.tagname_end = TAB;
  316.               }
  317.               else if (name_only)
  318.               {
  319.               if (get_it_again)
  320.               {
  321.                   char_u *temp_end = tagp.command;
  322.   
  323. !                 if (*temp_end == '/')
  324. !                 while (*temp_end && *temp_end != '\r'
  325. !                     && *temp_end != '\n'
  326. !                     && *temp_end != '$')
  327.                       temp_end++;
  328.   
  329. !                 if (tagp.command + 2 < temp_end)
  330.                   {
  331.                   len = (int)(temp_end - tagp.command - 2);
  332. !                 mfp = (struct match_found *)
  333. !                       alloc(sizeof(struct match_found) + len);
  334. !                 if (mfp != NULL)
  335. !                 {
  336. !                     mfp->len = len + 1; /* include the NUL */
  337. !                     p = mfp->match;
  338. !                     STRNCPY(p, tagp.command + 2, len);
  339. !                     p[len] = NUL;
  340. !                 }
  341.                   }
  342. +                 else
  343. +                 mfp = NULL;
  344.                   get_it_again = FALSE;
  345.               }
  346.               else
  347.               {
  348.                   len = (int)(tagp.tagname_end - tagp.tagname);
  349. !                 mfp = (struct match_found *)
  350. !                       alloc(sizeof(struct match_found) + len);
  351. !                 if (mfp != NULL)
  352. !                 {
  353. !                 mfp->len = len + 1; /* include the NUL */
  354. !                 p = mfp->match;
  355. !                 STRNCPY(p, tagp.tagname, len);
  356. !                 p[len] = NUL;
  357. !                 }
  358. !                 /* if wanted, re-read line to get long form too */
  359.                   if (State & INSERT)
  360.                   get_it_again = p_sft;
  361.               }
  362.               }
  363.               else
  364.               {
  365. ***************
  366. *** 1856,1864 ****
  367.               else
  368.                   ++len;
  369.   #endif
  370. !             p = alloc(len);
  371. !             if (p != NULL)
  372.               {
  373.                   p[0] = mtt;
  374.                   STRCPY(p + 1, tag_fname);
  375.   #ifdef BACKSLASH_IN_FILENAME
  376. --- 1890,1901 ----
  377.               else
  378.                   ++len;
  379.   #endif
  380. !             mfp = (struct match_found *)
  381. !                       alloc(sizeof(struct match_found) + len);
  382. !             if (mfp != NULL)
  383.               {
  384. +                 mfp->len = len;
  385. +                 p = mfp->match;
  386.                   p[0] = mtt;
  387.                   STRCPY(p + 1, tag_fname);
  388.   #ifdef BACKSLASH_IN_FILENAME
  389. ***************
  390. *** 1880,1886 ****
  391.               }
  392.               }
  393.   
  394. !             if (p != NULL)
  395.               {
  396.               /*
  397.                * Don't add identical matches.
  398. --- 1917,1923 ----
  399.               }
  400.               }
  401.   
  402. !             if (mfp != NULL)
  403.               {
  404.               /*
  405.                * Don't add identical matches.
  406. ***************
  407. *** 1895,1915 ****
  408.   #endif
  409.                 for (i = ga_match[mtt].ga_len; --i >= 0 && !got_int; )
  410.                 {
  411. !                 if (vim_memcmp(
  412. !                       ((char_u **)(ga_match[mtt].ga_data))[i],
  413. !                              p, (size_t)len) == 0)
  414. !                 break;
  415. !                 line_breakcheck();
  416.                 }
  417.               if (i < 0)
  418.               {
  419. !                 ((char_u **)(ga_match[mtt].ga_data))
  420. !                          [ga_match[mtt].ga_len++] = p;
  421.                   ga_match[mtt].ga_room--;
  422.                   ++match_count;
  423.               }
  424.               else
  425. !                 vim_free(p);
  426.               }
  427.           }
  428.           else    /* Out of memory! Just forget about the rest. */
  429. --- 1932,1954 ----
  430.   #endif
  431.                 for (i = ga_match[mtt].ga_len; --i >= 0 && !got_int; )
  432.                 {
  433. !                   mfp2 = ((struct match_found **)
  434. !                           (ga_match[mtt].ga_data))[i];
  435. !                   if (mfp2->len == mfp->len
  436. !                       && vim_memcmp(mfp2->match, mfp->match,
  437. !                                (size_t)mfp->len) == 0)
  438. !                   break;
  439. !                   line_breakcheck();
  440.                 }
  441.               if (i < 0)
  442.               {
  443. !                 ((struct match_found **)(ga_match[mtt].ga_data))
  444. !                            [ga_match[mtt].ga_len++] = mfp;
  445.                   ga_match[mtt].ga_room--;
  446.                   ++match_count;
  447.               }
  448.               else
  449. !                 vim_free(mfp);
  450.               }
  451.           }
  452.           else    /* Out of memory! Just forget about the rest. */
  453. ***************
  454. *** 2021,2031 ****
  455.       {
  456.       for (i = 0; i < ga_match[mtt].ga_len; ++i)
  457.       {
  458. !         p = ((char_u **)(ga_match[mtt].ga_data))[i];
  459.           if (matches == NULL)
  460. !         vim_free(p);
  461.           else
  462. !         matches[match_count++] = p;
  463.       }
  464.       ga_clear(&ga_match[mtt]);
  465.       }
  466. --- 2060,2077 ----
  467.       {
  468.       for (i = 0; i < ga_match[mtt].ga_len; ++i)
  469.       {
  470. !         mfp = ((struct match_found **)(ga_match[mtt].ga_data))[i];
  471.           if (matches == NULL)
  472. !         vim_free(mfp);
  473.           else
  474. !         {
  475. !         /* To avoid allocating memory again we turn the struct
  476. !          * match_found into a string.  For help the priority was not
  477. !          * included in the length. */
  478. !         mch_memmove(mfp, mfp->match,
  479. !                    (size_t)(mfp->len + (help_only ? 9 : 0)));
  480. !         matches[match_count++] = (char_u *)mfp;
  481. !         }
  482.       }
  483.       ga_clear(&ga_match[mtt]);
  484.       }
  485. *** ../vim-6.2.186/src/ui.c    Sat Sep 27 19:36:47 2003
  486. --- src/ui.c    Thu Jan 15 22:16:00 2004
  487. ***************
  488. *** 1539,1544 ****
  489. --- 1539,1545 ----
  490.   
  491.   /*
  492.    * Restore the input buffer with a pointer returned from get_input_buf().
  493. +  * The allocated memory is freed, this only works once!
  494.    */
  495.       void
  496.   set_input_buf(p)
  497. ***************
  498. *** 1546,1555 ****
  499.   {
  500.       garray_T    *gap = (garray_T *)p;
  501.   
  502. !     if (gap != NULL && gap->ga_data != NULL)
  503.       {
  504. !     mch_memmove(inbuf, gap->ga_data, gap->ga_len);
  505. !     inbufcount = gap->ga_len;
  506.       }
  507.   }
  508.   #endif
  509. --- 1547,1561 ----
  510.   {
  511.       garray_T    *gap = (garray_T *)p;
  512.   
  513. !     if (gap != NULL)
  514.       {
  515. !     if (gap->ga_data != NULL)
  516. !     {
  517. !         mch_memmove(inbuf, gap->ga_data, gap->ga_len);
  518. !         inbufcount = gap->ga_len;
  519. !         vim_free(gap->ga_data);
  520. !     }
  521. !     vim_free(gap);
  522.       }
  523.   }
  524.   #endif
  525. *** ../vim-6.2.186/src/version.c    Sun Jan 18 20:50:42 2004
  526. --- src/version.c    Sun Jan 18 20:52:09 2004
  527. ***************
  528. *** 639,640 ****
  529. --- 639,642 ----
  530.   {   /* Add new patch number below this line */
  531. + /**/
  532. +     187,
  533.   /**/
  534.  
  535. -- 
  536. ARTHUR:  I did say sorry about the `old woman,' but from the behind you
  537.          looked--
  538. DENNIS:  What I object to is you automatically treat me like an inferior!
  539. ARTHUR:  Well, I AM king...
  540.                                   The Quest for the Holy Grail (Monty Python)
  541.  
  542.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  543. ///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  544. \\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
  545.  \\\  Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html  ///
  546.