summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0959
blob: c7299e0f71d93789555184f371a9f6ceb38bdf2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0959
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 8.1.0959
Problem:    Sorting large numbers is not tested and does not work properly.
Solution:   Add test.  Fix comparing lines with and without a number.
            (Dominique Pelle, closes #4017)
Files:	    src/ex_cmds.c, src/testdir/test_sort.vim

*** ../vim-8.1.0958/src/ex_cmds.c	2019-02-17 17:44:36.203875545 +0100
--- src/ex_cmds.c	2019-02-20 22:15:27.631399246 +0100
***************
*** 303,309 ****
  	    varnumber_T	start_col_nr;		/* starting column number */
  	    varnumber_T	end_col_nr;		/* ending column number */
  	} line;
! 	varnumber_T	value;		/* value if sorting by integer */
  #ifdef FEAT_FLOAT
  	float_T value_flt;	/* value if sorting by float */
  #endif
--- 303,313 ----
  	    varnumber_T	start_col_nr;		/* starting column number */
  	    varnumber_T	end_col_nr;		/* ending column number */
  	} line;
! 	struct
! 	{
! 	    varnumber_T	value;		/* value if sorting by integer */
! 	    int is_number;		/* TRUE when line contains a number */
! 	} num;
  #ifdef FEAT_FLOAT
  	float_T value_flt;	/* value if sorting by float */
  #endif
***************
*** 335,345 ****
      if (got_int)
  	sort_abort = TRUE;
  
-     /* When sorting numbers "start_col_nr" is the number, not the column
-      * number. */
      if (sort_nr)
! 	result = l1.st_u.value == l2.st_u.value ? 0
! 				 : l1.st_u.value > l2.st_u.value ? 1 : -1;
  #ifdef FEAT_FLOAT
      else if (sort_flt)
  	result = l1.st_u.value_flt == l2.st_u.value_flt ? 0
--- 339,352 ----
      if (got_int)
  	sort_abort = TRUE;
  
      if (sort_nr)
!     {
! 	if (l1.st_u.num.is_number != l2.st_u.num.is_number)
! 	    result = l1.st_u.num.is_number - l2.st_u.num.is_number;
! 	else
! 	    result = l1.st_u.num.value == l2.st_u.num.value ? 0
! 			     : l1.st_u.num.value > l2.st_u.num.value ? 1 : -1;
!     }
  #ifdef FEAT_FLOAT
      else if (sort_flt)
  	result = l1.st_u.value_flt == l2.st_u.value_flt ? 0
***************
*** 553,563 ****
  		if (s > p && s[-1] == '-')
  		    --s;  /* include preceding negative sign */
  		if (*s == NUL)
! 		    /* empty line should sort before any number */
! 		    nrs[lnum - eap->line1].st_u.value = -MAXLNUM;
  		else
  		    vim_str2nr(s, NULL, NULL, sort_what,
! 			       &nrs[lnum - eap->line1].st_u.value, NULL, 0);
  	    }
  #ifdef FEAT_FLOAT
  	    else
--- 560,576 ----
  		if (s > p && s[-1] == '-')
  		    --s;  /* include preceding negative sign */
  		if (*s == NUL)
! 		{
! 		    /* line without number should sort before any number */
! 		    nrs[lnum - eap->line1].st_u.num.is_number = FALSE;
! 		    nrs[lnum - eap->line1].st_u.num.value = 0;
! 		}
  		else
+ 		{
+ 		    nrs[lnum - eap->line1].st_u.num.is_number = TRUE;
  		    vim_str2nr(s, NULL, NULL, sort_what,
! 			       &nrs[lnum - eap->line1].st_u.num.value, NULL, 0);
! 		}
  	    }
  #ifdef FEAT_FLOAT
  	    else
*** ../vim-8.1.0958/src/testdir/test_sort.vim	2018-09-21 12:46:16.341772938 +0200
--- src/testdir/test_sort.vim	2019-02-20 22:15:27.631399246 +0100
***************
*** 1222,1227 ****
--- 1222,1298 ----
    enew!
  endfunc
  
+ func Test_sort_large_num()
+   new
+   a
+ -2147483648
+ -2147483647
+ 
+ -1
+ 0
+ 1
+ -2147483646
+ 2147483646
+ 2147483647
+ 2147483647
+ -2147483648
+ abc
+ 
+ .
+   " Numerical sort. Non-numeric lines are ordered before numerical lines.
+   " Ordering of non-numerical is stable.
+   sort n
+   call assert_equal(['',
+   \                  'abc',
+   \                  '',
+   \                  '-2147483648',
+   \                  '-2147483648',
+   \                  '-2147483647',
+   \                  '-2147483646',
+   \                  '-1',
+   \                  '0',
+   \                  '1',
+   \                  '2147483646',
+   \                  '2147483647',
+   \                  '2147483647'], getline(1, '$'))
+   bwipe!
+ 
+   if has('num64')
+     new
+     a
+ -9223372036854775808
+ -9223372036854775807
+ 
+ -1
+ 0
+ 1
+ -9223372036854775806
+ 9223372036854775806
+ 9223372036854775807
+ 9223372036854775807
+ -9223372036854775808
+ abc
+ 
+ .
+     sort n
+     call assert_equal(['',
+     \                  'abc',
+     \                  '',
+     \                  '-9223372036854775808',
+     \                  '-9223372036854775808',
+     \                  '-9223372036854775807',
+     \                  '-9223372036854775806',
+     \                  '-1',
+     \                  '0',
+     \                  '1',
+     \                  '9223372036854775806',
+     \                  '9223372036854775807',
+     \                  '9223372036854775807'], getline(1, '$'))
+     bwipe!
+   endif
+ endfunc
+ 
+ 
  func Test_sort_cmd_report()
      enew!
      call append(0, repeat([1], 3) + repeat([2], 3) + repeat([3], 3))
*** ../vim-8.1.0958/src/version.c	2019-02-20 22:04:28.823721308 +0100
--- src/version.c	2019-02-20 22:17:16.762701596 +0100
***************
*** 781,782 ****
--- 781,784 ----
  {   /* Add new patch number below this line */
+ /**/
+     959,
  /**/


-- 
A consultant is a person who takes your money and annoys your employees while
tirelessly searching for the best way to extend the consulting contract.
				(Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///