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