3ef2ca
To: vim_dev@googlegroups.com
3ef2ca
Subject: Patch 7.4.411
3ef2ca
Fcc: outbox
3ef2ca
From: Bram Moolenaar <Bram@moolenaar.net>
3ef2ca
Mime-Version: 1.0
3ef2ca
Content-Type: text/plain; charset=UTF-8
3ef2ca
Content-Transfer-Encoding: 8bit
3ef2ca
------------
3ef2ca
3ef2ca
Patch 7.4.411
3ef2ca
Problem:    "foo bar" sorts before "foo" with sort(). (John Little)
3ef2ca
Solution:   Avoid putting quotes around strings before comparing them.
3ef2ca
Files:	    src/eval.c
3ef2ca
3ef2ca
3ef2ca
*** ../vim-7.4.410/src/eval.c	2014-08-06 14:52:05.043236174 +0200
3ef2ca
--- src/eval.c	2014-08-22 13:08:52.423905619 +0200
3ef2ca
***************
3ef2ca
*** 17382,17397 ****
3ef2ca
      const void	*s2;
3ef2ca
  {
3ef2ca
      sortItem_T  *si1, *si2;
3ef2ca
      char_u	*p1, *p2;
3ef2ca
!     char_u	*tofree1, *tofree2;
3ef2ca
      int		res;
3ef2ca
      char_u	numbuf1[NUMBUFLEN];
3ef2ca
      char_u	numbuf2[NUMBUFLEN];
3ef2ca
  
3ef2ca
      si1 = (sortItem_T *)s1;
3ef2ca
      si2 = (sortItem_T *)s2;
3ef2ca
!     p1 = tv2string(&si1->item->li_tv, &tofree1, numbuf1, 0);
3ef2ca
!     p2 = tv2string(&si2->item->li_tv, &tofree2, numbuf2, 0);
3ef2ca
      if (p1 == NULL)
3ef2ca
  	p1 = (char_u *)"";
3ef2ca
      if (p2 == NULL)
3ef2ca
--- 17382,17419 ----
3ef2ca
      const void	*s2;
3ef2ca
  {
3ef2ca
      sortItem_T  *si1, *si2;
3ef2ca
+     typval_T	*tv1, *tv2;
3ef2ca
      char_u	*p1, *p2;
3ef2ca
!     char_u	*tofree1 = NULL, *tofree2 = NULL;
3ef2ca
      int		res;
3ef2ca
      char_u	numbuf1[NUMBUFLEN];
3ef2ca
      char_u	numbuf2[NUMBUFLEN];
3ef2ca
  
3ef2ca
      si1 = (sortItem_T *)s1;
3ef2ca
      si2 = (sortItem_T *)s2;
3ef2ca
!     tv1 = &si1->item->li_tv;
3ef2ca
!     tv2 = &si2->item->li_tv;
3ef2ca
!     /* tv2string() puts quotes around a string and allocates memory.  Don't do
3ef2ca
!      * that for string variables. Use a single quote when comparing with a
3ef2ca
!      * non-string to do what the docs promise. */
3ef2ca
!     if (tv1->v_type == VAR_STRING)
3ef2ca
!     {
3ef2ca
! 	if (tv2->v_type != VAR_STRING || item_compare_numeric)
3ef2ca
! 	    p1 = (char_u *)"'";
3ef2ca
! 	else
3ef2ca
! 	    p1 = tv1->vval.v_string;
3ef2ca
!     }
3ef2ca
!     else
3ef2ca
! 	p1 = tv2string(tv1, &tofree1, numbuf1, 0);
3ef2ca
!     if (tv2->v_type == VAR_STRING)
3ef2ca
!     {
3ef2ca
! 	if (tv1->v_type != VAR_STRING || item_compare_numeric)
3ef2ca
! 	    p2 = (char_u *)"'";
3ef2ca
! 	else
3ef2ca
! 	    p2 = tv2->vval.v_string;
3ef2ca
!     }
3ef2ca
!     else
3ef2ca
! 	p2 = tv2string(tv2, &tofree2, numbuf2, 0);
3ef2ca
      if (p1 == NULL)
3ef2ca
  	p1 = (char_u *)"";
3ef2ca
      if (p2 == NULL)
3ef2ca
***************
3ef2ca
*** 17411,17418 ****
3ef2ca
  	res = n1 == n2 ? 0 : n1 > n2 ? 1 : -1;
3ef2ca
      }
3ef2ca
  
3ef2ca
!     /* When the result would be zero, compare the pointers themselves.  Makes
3ef2ca
!      * the sort stable. */
3ef2ca
      if (res == 0 && !item_compare_keep_zero)
3ef2ca
  	res = si1->idx > si2->idx ? 1 : -1;
3ef2ca
  
3ef2ca
--- 17433,17440 ----
3ef2ca
  	res = n1 == n2 ? 0 : n1 > n2 ? 1 : -1;
3ef2ca
      }
3ef2ca
  
3ef2ca
!     /* When the result would be zero, compare the item indexes.  Makes the
3ef2ca
!      * sort stable. */
3ef2ca
      if (res == 0 && !item_compare_keep_zero)
3ef2ca
  	res = si1->idx > si2->idx ? 1 : -1;
3ef2ca
  
3ef2ca
*** ../vim-7.4.410/src/version.c	2014-08-17 17:24:03.967017727 +0200
3ef2ca
--- src/version.c	2014-08-22 12:51:35.011943243 +0200
3ef2ca
***************
3ef2ca
*** 743,744 ****
3ef2ca
--- 743,746 ----
3ef2ca
  {   /* Add new patch number below this line */
3ef2ca
+ /**/
3ef2ca
+     411,
3ef2ca
  /**/
3ef2ca
3ef2ca
-- 
3ef2ca
I started out with nothing, and I still have most of it.
3ef2ca
                                -- Michael Davis -- "Tonight Show"
3ef2ca
3ef2ca
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
3ef2ca
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
3ef2ca
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
3ef2ca
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///