Karsten Hopp 3f6673
To: vim-dev@vim.org
Karsten Hopp 3f6673
Subject: patch 7.1.074
Karsten Hopp 3f6673
Fcc: outbox
Karsten Hopp 3f6673
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 3f6673
Mime-Version: 1.0
Karsten Hopp 3f6673
Content-Type: text/plain; charset=ISO-8859-1
Karsten Hopp 3f6673
Content-Transfer-Encoding: 8bit
Karsten Hopp 3f6673
------------
Karsten Hopp 3f6673
Karsten Hopp 3f6673
Patch 7.1.074
Karsten Hopp 3f6673
Problem:    Crash when calling string() on a recurively nested List.
Karsten Hopp 3f6673
Solution:   Check result value for being NULL. (Yukihiro Nakadaira)
Karsten Hopp 3f6673
Files:	    src/eval.c
Karsten Hopp 3f6673
Karsten Hopp 3f6673
Karsten Hopp 3f6673
*** ../vim-7.1.073/src/eval.c	Mon Aug  6 22:27:12 2007
Karsten Hopp 3f6673
--- src/eval.c	Tue Aug 14 22:01:12 2007
Karsten Hopp 3f6673
***************
Karsten Hopp 3f6673
*** 6802,6808 ****
Karsten Hopp 3f6673
   * "numbuf" is used for a number.
Karsten Hopp 3f6673
   * Does not put quotes around strings, as ":echo" displays values.
Karsten Hopp 3f6673
   * When "copyID" is not NULL replace recursive lists and dicts with "...".
Karsten Hopp 3f6673
!  * May return NULL;
Karsten Hopp 3f6673
   */
Karsten Hopp 3f6673
      static char_u *
Karsten Hopp 3f6673
  echo_string(tv, tofree, numbuf, copyID)
Karsten Hopp 3f6673
--- 6802,6808 ----
Karsten Hopp 3f6673
   * "numbuf" is used for a number.
Karsten Hopp 3f6673
   * Does not put quotes around strings, as ":echo" displays values.
Karsten Hopp 3f6673
   * When "copyID" is not NULL replace recursive lists and dicts with "...".
Karsten Hopp 3f6673
!  * May return NULL.
Karsten Hopp 3f6673
   */
Karsten Hopp 3f6673
      static char_u *
Karsten Hopp 3f6673
  echo_string(tv, tofree, numbuf, copyID)
Karsten Hopp 3f6673
***************
Karsten Hopp 3f6673
*** 6887,6893 ****
Karsten Hopp 3f6673
   * If the memory is allocated "tofree" is set to it, otherwise NULL.
Karsten Hopp 3f6673
   * "numbuf" is used for a number.
Karsten Hopp 3f6673
   * Puts quotes around strings, so that they can be parsed back by eval().
Karsten Hopp 3f6673
!  * May return NULL;
Karsten Hopp 3f6673
   */
Karsten Hopp 3f6673
      static char_u *
Karsten Hopp 3f6673
  tv2string(tv, tofree, numbuf, copyID)
Karsten Hopp 3f6673
--- 6887,6893 ----
Karsten Hopp 3f6673
   * If the memory is allocated "tofree" is set to it, otherwise NULL.
Karsten Hopp 3f6673
   * "numbuf" is used for a number.
Karsten Hopp 3f6673
   * Puts quotes around strings, so that they can be parsed back by eval().
Karsten Hopp 3f6673
!  * May return NULL.
Karsten Hopp 3f6673
   */
Karsten Hopp 3f6673
      static char_u *
Karsten Hopp 3f6673
  tv2string(tv, tofree, numbuf, copyID)
Karsten Hopp 3f6673
***************
Karsten Hopp 3f6673
*** 14974,14979 ****
Karsten Hopp 3f6673
--- 14974,14983 ----
Karsten Hopp 3f6673
  
Karsten Hopp 3f6673
      p1 = tv2string(&(*(listitem_T **)s1)->li_tv, &tofree1, numbuf1, 0);
Karsten Hopp 3f6673
      p2 = tv2string(&(*(listitem_T **)s2)->li_tv, &tofree2, numbuf2, 0);
Karsten Hopp 3f6673
+     if (p1 == NULL)
Karsten Hopp 3f6673
+ 	p1 = (char_u *)"";
Karsten Hopp 3f6673
+     if (p2 == NULL)
Karsten Hopp 3f6673
+ 	p2 = (char_u *)"";
Karsten Hopp 3f6673
      if (item_compare_ic)
Karsten Hopp 3f6673
  	res = STRICMP(p1, p2);
Karsten Hopp 3f6673
      else
Karsten Hopp 3f6673
***************
Karsten Hopp 3f6673
*** 15463,15469 ****
Karsten Hopp 3f6673
  
Karsten Hopp 3f6673
      rettv->v_type = VAR_STRING;
Karsten Hopp 3f6673
      rettv->vval.v_string = tv2string(&argvars[0], &tofree, numbuf, 0);
Karsten Hopp 3f6673
!     if (tofree == NULL)
Karsten Hopp 3f6673
  	rettv->vval.v_string = vim_strsave(rettv->vval.v_string);
Karsten Hopp 3f6673
  }
Karsten Hopp 3f6673
  
Karsten Hopp 3f6673
--- 15467,15474 ----
Karsten Hopp 3f6673
  
Karsten Hopp 3f6673
      rettv->v_type = VAR_STRING;
Karsten Hopp 3f6673
      rettv->vval.v_string = tv2string(&argvars[0], &tofree, numbuf, 0);
Karsten Hopp 3f6673
!     /* Make a copy if we have a value but it's not in allocate memory. */
Karsten Hopp 3f6673
!     if (rettv->vval.v_string != NULL && tofree == NULL)
Karsten Hopp 3f6673
  	rettv->vval.v_string = vim_strsave(rettv->vval.v_string);
Karsten Hopp 3f6673
  }
Karsten Hopp 3f6673
  
Karsten Hopp 3f6673
***************
Karsten Hopp 3f6673
*** 20167,20172 ****
Karsten Hopp 3f6673
--- 20174,20180 ----
Karsten Hopp 3f6673
  		char_u	buf[MSG_BUF_LEN];
Karsten Hopp 3f6673
  		char_u	numbuf2[NUMBUFLEN];
Karsten Hopp 3f6673
  		char_u	*tofree;
Karsten Hopp 3f6673
+ 		char_u	*s;
Karsten Hopp 3f6673
  
Karsten Hopp 3f6673
  		msg_puts((char_u *)"(");
Karsten Hopp 3f6673
  		for (i = 0; i < argcount; ++i)
Karsten Hopp 3f6673
***************
Karsten Hopp 3f6673
*** 20177,20186 ****
Karsten Hopp 3f6673
  			msg_outnum((long)argvars[i].vval.v_number);
Karsten Hopp 3f6673
  		    else
Karsten Hopp 3f6673
  		    {
Karsten Hopp 3f6673
! 			trunc_string(tv2string(&argvars[i], &tofree,
Karsten Hopp 3f6673
! 					      numbuf2, 0), buf, MSG_BUF_CLEN);
Karsten Hopp 3f6673
! 			msg_puts(buf);
Karsten Hopp 3f6673
! 			vim_free(tofree);
Karsten Hopp 3f6673
  		    }
Karsten Hopp 3f6673
  		}
Karsten Hopp 3f6673
  		msg_puts((char_u *)")");
Karsten Hopp 3f6673
--- 20185,20197 ----
Karsten Hopp 3f6673
  			msg_outnum((long)argvars[i].vval.v_number);
Karsten Hopp 3f6673
  		    else
Karsten Hopp 3f6673
  		    {
Karsten Hopp 3f6673
! 			s = tv2string(&argvars[i], &tofree, numbuf2, 0);
Karsten Hopp 3f6673
! 			if (s != NULL)
Karsten Hopp 3f6673
! 			{
Karsten Hopp 3f6673
! 			    trunc_string(s, buf, MSG_BUF_CLEN);
Karsten Hopp 3f6673
! 			    msg_puts(buf);
Karsten Hopp 3f6673
! 			    vim_free(tofree);
Karsten Hopp 3f6673
! 			}
Karsten Hopp 3f6673
  		    }
Karsten Hopp 3f6673
  		}
Karsten Hopp 3f6673
  		msg_puts((char_u *)")");
Karsten Hopp 3f6673
***************
Karsten Hopp 3f6673
*** 20258,20271 ****
Karsten Hopp 3f6673
  	    char_u	buf[MSG_BUF_LEN];
Karsten Hopp 3f6673
  	    char_u	numbuf2[NUMBUFLEN];
Karsten Hopp 3f6673
  	    char_u	*tofree;
Karsten Hopp 3f6673
  
Karsten Hopp 3f6673
  	    /* The value may be very long.  Skip the middle part, so that we
Karsten Hopp 3f6673
  	     * have some idea how it starts and ends. smsg() would always
Karsten Hopp 3f6673
  	     * truncate it at the end. */
Karsten Hopp 3f6673
! 	    trunc_string(tv2string(fc.rettv, &tofree, numbuf2, 0),
Karsten Hopp 3f6673
! 							   buf, MSG_BUF_CLEN);
Karsten Hopp 3f6673
! 	    smsg((char_u *)_("%s returning %s"), sourcing_name, buf);
Karsten Hopp 3f6673
! 	    vim_free(tofree);
Karsten Hopp 3f6673
  	}
Karsten Hopp 3f6673
  	msg_puts((char_u *)"\n");   /* don't overwrite this either */
Karsten Hopp 3f6673
  
Karsten Hopp 3f6673
--- 20269,20286 ----
Karsten Hopp 3f6673
  	    char_u	buf[MSG_BUF_LEN];
Karsten Hopp 3f6673
  	    char_u	numbuf2[NUMBUFLEN];
Karsten Hopp 3f6673
  	    char_u	*tofree;
Karsten Hopp 3f6673
+ 	    char_u	*s;
Karsten Hopp 3f6673
  
Karsten Hopp 3f6673
  	    /* The value may be very long.  Skip the middle part, so that we
Karsten Hopp 3f6673
  	     * have some idea how it starts and ends. smsg() would always
Karsten Hopp 3f6673
  	     * truncate it at the end. */
Karsten Hopp 3f6673
! 	    s = tv2string(fc.rettv, &tofree, numbuf2, 0);
Karsten Hopp 3f6673
! 	    if (s != NULL)
Karsten Hopp 3f6673
! 	    {
Karsten Hopp 3f6673
! 		trunc_string(s, buf, MSG_BUF_CLEN);
Karsten Hopp 3f6673
! 		smsg((char_u *)_("%s returning %s"), sourcing_name, buf);
Karsten Hopp 3f6673
! 		vim_free(tofree);
Karsten Hopp 3f6673
! 	    }
Karsten Hopp 3f6673
  	}
Karsten Hopp 3f6673
  	msg_puts((char_u *)"\n");   /* don't overwrite this either */
Karsten Hopp 3f6673
  
Karsten Hopp 3f6673
*** ../vim-7.1.073/src/version.c	Tue Aug 14 22:15:53 2007
Karsten Hopp 3f6673
--- src/version.c	Tue Aug 14 22:27:24 2007
Karsten Hopp 3f6673
***************
Karsten Hopp 3f6673
*** 668,669 ****
Karsten Hopp 3f6673
--- 668,671 ----
Karsten Hopp 3f6673
  {   /* Add new patch number below this line */
Karsten Hopp 3f6673
+ /**/
Karsten Hopp 3f6673
+     74,
Karsten Hopp 3f6673
  /**/
Karsten Hopp 3f6673
Karsten Hopp 3f6673
-- 
Karsten Hopp 3f6673
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 3f6673
159. You get excited whenever discussing your hard drive.
Karsten Hopp 3f6673
Karsten Hopp 3f6673
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 3f6673
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 3f6673
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 3f6673
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///