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.369 < prev    next >
Encoding:
Internet Message Format  |  2004-03-16  |  14.0 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 6.2.369
  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.369
  11. Problem:    Various memory leaks: when using globpath(), when searching for
  12.         help tags files, when defining a function inside a function, when
  13.         giving an error message through an exception, for the final "."
  14.         line in ":append", in expression "cond ? a : b" that fails and for
  15.         missing ")" in an expression.  Using NULL pointer when adding
  16.         first user command and for pointer computations with regexp.
  17.         (tests by Dominique Pelle)
  18. Solution:   Fix the leaks by freeing the allocated memory.  Don't use the
  19.         array of user commands when there are no entries.  Use a macro
  20.         instead of a function call for saving and restoring regexp states.
  21. Files:        src/eval.c, src/ex_cmds.c, src/ex_docmd.c, src/ex_getln.c,
  22.         src/misc2.c, src/regexp.c, src/screen.c, src/tag.c
  23.  
  24.  
  25. *** ../vim-6.2.368/src/eval.c    Fri Feb 20 22:11:01 2004
  26. --- src/eval.c    Wed Mar 17 11:38:47 2004
  27. ***************
  28. *** 1690,1695 ****
  29. --- 1690,1697 ----
  30.       if ((*arg)[0] != ':')
  31.       {
  32.           EMSG(_("E109: Missing ':' after '?'"));
  33. +         if (evaluate && result)
  34. +         clear_var(retvar);
  35.           return FAIL;
  36.       }
  37.   
  38. ***************
  39. *** 1698,1704 ****
  40. --- 1700,1710 ----
  41.        */
  42.       *arg = skipwhite(*arg + 1);
  43.       if (eval1(arg, &var2, evaluate && !result) == FAIL) /* recursive! */
  44. +     {
  45. +         if (evaluate && result)
  46. +         clear_var(retvar);
  47.           return FAIL;
  48. +     }
  49.       if (evaluate && !result)
  50.           *retvar = var2;
  51.       }
  52. ***************
  53. *** 1734,1743 ****
  54.       /*
  55.        * Repeat until there is no following "||".
  56.        */
  57.       while ((*arg)[0] == '|' && (*arg)[1] == '|')
  58.       {
  59. -     result = FALSE;
  60. -     first = TRUE;
  61.       if (evaluate && first)
  62.       {
  63.           if (get_var_number(retvar) != 0)
  64. --- 1740,1749 ----
  65.       /*
  66.        * Repeat until there is no following "||".
  67.        */
  68. +     first = TRUE;
  69. +     result = FALSE;
  70.       while ((*arg)[0] == '|' && (*arg)[1] == '|')
  71.       {
  72.       if (evaluate && first)
  73.       {
  74.           if (get_var_number(retvar) != 0)
  75. ***************
  76. *** 1800,1809 ****
  77.       /*
  78.        * Repeat until there is no following "&&".
  79.        */
  80.       while ((*arg)[0] == '&' && (*arg)[1] == '&')
  81.       {
  82. -     result = TRUE;
  83. -     first = TRUE;
  84.       if (evaluate && first)
  85.       {
  86.           if (get_var_number(retvar) == 0)
  87. --- 1806,1815 ----
  88.       /*
  89.        * Repeat until there is no following "&&".
  90.        */
  91. +     first = TRUE;
  92. +     result = TRUE;
  93.       while ((*arg)[0] == '&' && (*arg)[1] == '&')
  94.       {
  95.       if (evaluate && first)
  96.       {
  97.           if (get_var_number(retvar) == 0)
  98. ***************
  99. *** 2306,2311 ****
  100. --- 2312,2318 ----
  101.           else if (ret == OK)
  102.           {
  103.               EMSG(_("E110: Missing ')'"));
  104. +             clear_var(retvar);
  105.               ret = FAIL;
  106.           }
  107.           break;
  108. ***************
  109. *** 2331,2337 ****
  110. --- 2338,2348 ----
  111.                * aborting on error, or when an interrupt occurred or
  112.                * an exception was thrown but not caught. */
  113.               if (aborting())
  114. +             {
  115. +                 if (ret == OK)
  116. +                 clear_var(retvar);
  117.                   ret = FAIL;
  118. +             }
  119.               }
  120.               else if (evaluate)
  121.               ret = get_var_var(s, len, retvar);
  122. ***************
  123. *** 2364,2369 ****
  124. --- 2375,2381 ----
  125.       {
  126.           EMSG(_("E111: Missing ']'"));
  127.           clear_var(retvar);
  128. +         clear_var(&var2);
  129.           return FAIL;
  130.       }
  131.   
  132. ***************
  133. *** 6929,6941 ****
  134.       int        slen;
  135.   
  136.       p = get_var_string(&argvars[0]);
  137.       n = get_var_number(&argvars[1]);
  138.       if (argvars[2].var_type != VAR_UNKNOWN)
  139.       len = get_var_number(&argvars[2]);
  140.       else
  141. !     len = (int)STRLEN(p) - n;
  142.   
  143. -     slen = (int)STRLEN(p);
  144.       /*
  145.        * Only return the overlap between the specified part and the actual
  146.        * string.
  147. --- 6941,6954 ----
  148.       int        slen;
  149.   
  150.       p = get_var_string(&argvars[0]);
  151. +     slen = (int)STRLEN(p);
  152.       n = get_var_number(&argvars[1]);
  153.       if (argvars[2].var_type != VAR_UNKNOWN)
  154.       len = get_var_number(&argvars[2]);
  155.       else
  156. !     len = slen - n;        /* default len: all bytes that are available. */
  157.   
  158.       /*
  159.        * Only return the overlap between the specified part and the actual
  160.        * string.
  161. ***************
  162. *** 8920,8926 ****
  163.           p += eval_fname_script(p);
  164.           if (ASCII_ISALPHA(*p))
  165.           {
  166. !             (void)trans_function_name(&p, TRUE, FALSE);
  167.               if (*skipwhite(p) == '(')
  168.               {
  169.               ++nesting;
  170. --- 8933,8939 ----
  171.           p += eval_fname_script(p);
  172.           if (ASCII_ISALPHA(*p))
  173.           {
  174. !             vim_free(trans_function_name(&p, TRUE, FALSE));
  175.               if (*skipwhite(p) == '(')
  176.               {
  177.               ++nesting;
  178. *** ../vim-6.2.368/src/ex_cmds.c    Mon Mar 15 12:33:19 2004
  179. --- src/ex_cmds.c    Wed Mar 17 10:20:59 2004
  180. ***************
  181. *** 3238,3248 ****
  182.   #endif
  183.               NUL, eap->cookie, 0);
  184.       lines_left = Rows - 1;
  185. !     if (theline == NULL || (theline[0] == '.' && theline[1] == NUL))
  186.           break;
  187.   
  188. -     if (!did_undo && u_save(lnum, lnum + 1) == FAIL)
  189. -         break;
  190.       did_undo = TRUE;
  191.       ml_append(lnum, theline, (colnr_T)0, FALSE);
  192.       appended_lines_mark(lnum, 1L);
  193. --- 3238,3250 ----
  194.   #endif
  195.               NUL, eap->cookie, 0);
  196.       lines_left = Rows - 1;
  197. !     if (theline == NULL || (theline[0] == '.' && theline[1] == NUL)
  198. !         || (!did_undo && u_save(lnum, lnum + 1) == FAIL))
  199. !     {
  200. !         vim_free(theline);
  201.           break;
  202. +     }
  203.   
  204.       did_undo = TRUE;
  205.       ml_append(lnum, theline, (colnr_T)0, FALSE);
  206.       appended_lines_mark(lnum, 1L);
  207. *** ../vim-6.2.368/src/ex_docmd.c    Mon Mar  8 15:22:09 2004
  208. --- src/ex_docmd.c    Tue Mar 16 12:00:49 2004
  209. ***************
  210. *** 1261,1266 ****
  211. --- 1261,1267 ----
  212.           emsg(p);
  213.           vim_free(p);
  214.           }
  215. +         vim_free(sourcing_name);
  216.           sourcing_name = saved_sourcing_name;
  217.           sourcing_lnum = saved_sourcing_lnum;
  218.       }
  219. ***************
  220. *** 2650,2659 ****
  221.           gap = &curbuf->b_ucmds;
  222.           for (;;)
  223.           {
  224. !         cmd = USER_CMD_GA(gap, 0);
  225. !         for (j = 0; j < gap->ga_len; ++j, ++cmd)
  226.           {
  227.               cp = eap->cmd;
  228.               np = cmd->uc_name;
  229.               k = 0;
  230. --- 2649,2657 ----
  231.           gap = &curbuf->b_ucmds;
  232.           for (;;)
  233.           {
  234. !         for (j = 0; j < gap->ga_len; ++j)
  235.           {
  236. +             cmd = USER_CMD_GA(gap, j);
  237.               cp = eap->cmd;
  238.               np = cmd->uc_name;
  239.               k = 0;
  240. ***************
  241. *** 4579,4585 ****
  242.       char_u    *compl_arg;
  243.       int        force;
  244.   {
  245. !     ucmd_T    *cmd;
  246.       char_u    *p;
  247.       int        i;
  248.       int        cmp = 1;
  249. --- 4577,4583 ----
  250.       char_u    *compl_arg;
  251.       int        force;
  252.   {
  253. !     ucmd_T    *cmd = NULL;
  254.       char_u    *p;
  255.       int        i;
  256.       int        cmp = 1;
  257. ***************
  258. *** 4607,4619 ****
  259.       else
  260.       gap = &ucmds;
  261.   
  262. !     /* Search for the command */
  263. !     cmd = USER_CMD_GA(gap, 0);
  264. !     i = 0;
  265. !     while (i < gap->ga_len)
  266.       {
  267. !     size_t len = STRLEN(cmd->uc_name);
  268.   
  269.       cmp = STRNCMP(name, cmd->uc_name, name_len);
  270.       if (cmp == 0)
  271.       {
  272. --- 4605,4617 ----
  273.       else
  274.       gap = &ucmds;
  275.   
  276. !     /* Search for the command in the already defined commands. */
  277. !     for (i = 0; i < gap->ga_len; ++i)
  278.       {
  279. !     size_t len;
  280.   
  281. +     cmd = USER_CMD_GA(gap, i);
  282. +     len = STRLEN(cmd->uc_name);
  283.       cmp = STRNCMP(name, cmd->uc_name, name_len);
  284.       if (cmp == 0)
  285.       {
  286. ***************
  287. *** 4639,4647 ****
  288.       /* Stop as soon as we pass the name to add */
  289.       if (cmp < 0)
  290.           break;
  291. -     ++cmd;
  292. -     ++i;
  293.       }
  294.   
  295.       /* Extend the array unless we're replacing an existing command */
  296. --- 4637,4642 ----
  297. ***************
  298. *** 5124,5143 ****
  299.       exarg_T    *eap;
  300.   {
  301.       int        i = 0;
  302. !     ucmd_T    *cmd;
  303.       int        cmp = -1;
  304.       garray_T    *gap;
  305.   
  306.       gap = &curbuf->b_ucmds;
  307.       for (;;)
  308.       {
  309. -     cmd = USER_CMD_GA(gap, 0);
  310.       for (i = 0; i < gap->ga_len; ++i)
  311.       {
  312.           cmp = STRCMP(eap->arg, cmd->uc_name);
  313.           if (cmp <= 0)
  314.           break;
  315. -         ++cmd;
  316.       }
  317.       if (gap == &ucmds || cmp == 0)
  318.           break;
  319. --- 5119,5137 ----
  320.       exarg_T    *eap;
  321.   {
  322.       int        i = 0;
  323. !     ucmd_T    *cmd = NULL;
  324.       int        cmp = -1;
  325.       garray_T    *gap;
  326.   
  327.       gap = &curbuf->b_ucmds;
  328.       for (;;)
  329.       {
  330.       for (i = 0; i < gap->ga_len; ++i)
  331.       {
  332. +         cmd = USER_CMD_GA(gap, i);
  333.           cmp = STRCMP(eap->arg, cmd->uc_name);
  334.           if (cmp <= 0)
  335.           break;
  336.       }
  337.       if (gap == &ucmds || cmp == 0)
  338.           break;
  339. *** ../vim-6.2.368/src/ex_getln.c    Sun Feb 29 21:06:13 2004
  340. --- src/ex_getln.c    Tue Mar 16 10:41:32 2004
  341. ***************
  342. *** 2048,2055 ****
  343.   redrawcmd_preedit()
  344.   {
  345.       if ((State & CMDLINE)
  346. !     && xic != NULL && im_get_status() && !p_imdisable
  347. !     && preedit_start_col != MAXCOL)
  348.       {
  349.       int    cmdpos = 0;
  350.       int    cmdspos;
  351. --- 2048,2057 ----
  352.   redrawcmd_preedit()
  353.   {
  354.       if ((State & CMDLINE)
  355. !         && xic != NULL
  356. !         && im_get_status()
  357. !         && !p_imdisable
  358. !         && preedit_start_col != MAXCOL)
  359.       {
  360.       int    cmdpos = 0;
  361.       int    cmdspos;
  362. ***************
  363. *** 4057,4062 ****
  364. --- 4059,4065 ----
  365.               ga.ga_len += len;
  366.               ga.ga_room -= len;
  367.           }
  368. +         FreeWild(num_p, p);
  369.           }
  370.       }
  371.       }
  372. *** ../vim-6.2.368/src/misc2.c    Mon Mar 15 12:44:12 2004
  373. --- src/misc2.c    Tue Mar 16 11:07:16 2004
  374. ***************
  375. *** 1500,1506 ****
  376.       ga_init(gap);
  377.   }
  378.   
  379. - #if defined(FEAT_EVAL) || defined(PROTO)
  380.   /*
  381.    * Clear a growing array that contains a list of strings.
  382.    */
  383. --- 1500,1505 ----
  384. ***************
  385. *** 1514,1520 ****
  386.       vim_free(((char_u **)(gap->ga_data))[i]);
  387.       ga_clear(gap);
  388.   }
  389. - #endif
  390.   
  391.   /*
  392.    * Initialize a growing array.    Don't forget to set ga_itemsize and
  393. --- 1513,1518 ----
  394. *** ../vim-6.2.368/src/regexp.c    Sun Feb 15 13:49:38 2004
  395. --- src/regexp.c    Tue Mar 16 11:34:06 2004
  396. ***************
  397. *** 2611,2618 ****
  398.   static void    reg_save __ARGS((regsave_T *save));
  399.   static void    reg_restore __ARGS((regsave_T *save));
  400.   static int    reg_save_equal __ARGS((regsave_T *save));
  401. ! static void    save_se __ARGS((save_se_T *savep, lpos_T *posp, char_u **pp));
  402. ! static void    restore_se __ARGS((save_se_T *savep, lpos_T *posp, char_u **pp));
  403.   static int    re_num_cmp __ARGS((long_u val, char_u *scan));
  404.   static int    regmatch __ARGS((char_u *prog));
  405.   static int    regrepeat __ARGS((char_u *p, long maxcount));
  406. --- 2611,2630 ----
  407.   static void    reg_save __ARGS((regsave_T *save));
  408.   static void    reg_restore __ARGS((regsave_T *save));
  409.   static int    reg_save_equal __ARGS((regsave_T *save));
  410. ! static void    save_se_multi __ARGS((save_se_T *savep, lpos_T *posp));
  411. ! static void    save_se_one __ARGS((save_se_T *savep, char_u **pp));
  412. ! /* Save the sub-expressions before attempting a match. */
  413. ! #define save_se(savep, posp, pp) \
  414. !     REG_MULTI ? save_se_multi((savep), (posp)) : save_se_one((savep), (pp))
  415. ! /* After a failed match restore the sub-expressions. */
  416. ! #define restore_se(savep, posp, pp) { \
  417. !     if (REG_MULTI) \
  418. !     *(posp) = (savep)->se_u.pos; \
  419. !     else \
  420. !     *(pp) = (savep)->se_u.ptr; }
  421.   static int    re_num_cmp __ARGS((long_u val, char_u *scan));
  422.   static int    regmatch __ARGS((char_u *prog));
  423.   static int    regrepeat __ARGS((char_u *p, long maxcount));
  424. ***************
  425. *** 4747,4786 ****
  426.    * Tentatively set the sub-expression start to the current position (after
  427.    * calling regmatch() they will have changed).  Need to save the existing
  428.    * values for when there is no match.
  429. !  * Use pointer or position, depending on REG_MULTI.
  430.    */
  431.       static void
  432. ! save_se(savep, posp, pp)
  433.       save_se_T    *savep;
  434.       lpos_T    *posp;
  435. -     char_u    **pp;
  436.   {
  437. !     if (REG_MULTI)
  438. !     {
  439. !     savep->se_u.pos = *posp;
  440. !     posp->lnum = reglnum;
  441. !     posp->col = (colnr_T)(reginput - regline);
  442. !     }
  443. !     else
  444. !     {
  445. !     savep->se_u.ptr = *pp;
  446. !     *pp = reginput;
  447. !     }
  448.   }
  449.   
  450. - /*
  451. -  * We were wrong, restore the sub-expressions.
  452. -  */
  453.       static void
  454. ! restore_se(savep, posp, pp)
  455.       save_se_T    *savep;
  456. -     lpos_T    *posp;
  457.       char_u    **pp;
  458.   {
  459. !     if (REG_MULTI)
  460. !     *posp = savep->se_u.pos;
  461. !     else
  462. !     *pp = savep->se_u.ptr;
  463.   }
  464.   
  465.   /*
  466. --- 4759,4784 ----
  467.    * Tentatively set the sub-expression start to the current position (after
  468.    * calling regmatch() they will have changed).  Need to save the existing
  469.    * values for when there is no match.
  470. !  * Use se_save() to use pointer (save_se_multi()) or position (save_se_one()),
  471. !  * depending on REG_MULTI.
  472.    */
  473.       static void
  474. ! save_se_multi(savep, posp)
  475.       save_se_T    *savep;
  476.       lpos_T    *posp;
  477.   {
  478. !     savep->se_u.pos = *posp;
  479. !     posp->lnum = reglnum;
  480. !     posp->col = (colnr_T)(reginput - regline);
  481.   }
  482.   
  483.       static void
  484. ! save_se_one(savep, pp)
  485.       save_se_T    *savep;
  486.       char_u    **pp;
  487.   {
  488. !     savep->se_u.ptr = *pp;
  489. !     *pp = reginput;
  490.   }
  491.   
  492.   /*
  493. *** ../vim-6.2.368/src/screen.c    Tue Mar 16 15:35:40 2004
  494. --- src/screen.c    Wed Mar 17 12:40:59 2004
  495. ***************
  496. *** 1599,1604 ****
  497. --- 1599,1613 ----
  498.                   wp->w_lines_valid = wp->w_height;
  499.                   for (i = wp->w_lines_valid; i - j >= idx; --i)
  500.                   wp->w_lines[i] = wp->w_lines[i - j];
  501. +                 /* The w_lines[] entries for inserted lines are
  502. +                  * now invalid, but wl_size may be used above.
  503. +                  * Reset to zero. */
  504. +                 while (i >= idx)
  505. +                 {
  506. +                 wp->w_lines[i].wl_size = 0;
  507. +                 wp->w_lines[i--].wl_valid = FALSE;
  508. +                 }
  509.               }
  510.               }
  511.           }
  512. *** ../vim-6.2.368/src/tag.c    Sun Feb 29 21:06:13 2004
  513. --- src/tag.c    Tue Mar 16 11:06:16 2004
  514. ***************
  515. *** 2226,2232 ****
  516.            * For a help window find "doc/tags" and "doc/tags-??" in all
  517.            * directories in 'runtimepath'.
  518.            */
  519. !         ga_clear(&tag_fnames);
  520.           ga_init2(&tag_fnames, sizeof(char_u *), 10);
  521.           do_in_runtimepath((char_u *)
  522.   #ifdef FEAT_MULTI_LANG
  523. --- 2226,2232 ----
  524.            * For a help window find "doc/tags" and "doc/tags-??" in all
  525.            * directories in 'runtimepath'.
  526.            */
  527. !         ga_clear_strings(&tag_fnames);
  528.           ga_init2(&tag_fnames, sizeof(char_u *), 10);
  529.           do_in_runtimepath((char_u *)
  530.   #ifdef FEAT_MULTI_LANG
  531. *** ../vim-6.2.368/src/version.c    Wed Mar 17 09:54:22 2004
  532. --- src/version.c    Wed Mar 17 13:04:59 2004
  533. ***************
  534. *** 639,640 ****
  535. --- 639,642 ----
  536.   {   /* Add new patch number below this line */
  537. + /**/
  538. +     369,
  539.   /**/
  540.  
  541. -- 
  542. I started out with nothing, and I still have most of it.
  543.                                 -- Michael Davis -- "Tonight Show"
  544.  
  545.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  546. ///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  547. \\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
  548.  \\\  Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///
  549.