summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2014-08-22 13:13:27 +0200
committerBram Moolenaar <Bram@vim.org>2014-08-22 13:13:27 +0200
commit1b338d2022cb28fe143b134a966f13f18d14596c (patch)
tree6ca3968c5cd8a8a8ef01c43c375fb5f834915fb0
parent42f06f9dbc1e167a8ddef2ec500d952870600d5e (diff)
updated for version 7.4.411v7.4.411
Problem: "foo bar" sorts before "foo" with sort(). (John Little) Solution: Avoid putting quotes around strings before comparing them.
-rw-r--r--src/eval.c32
-rw-r--r--src/version.c2
2 files changed, 29 insertions, 5 deletions
diff --git a/src/eval.c b/src/eval.c
index ae8331d5aa..654e4187d5 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -17382,16 +17382,38 @@ item_compare(s1, s2)
const void *s2;
{
sortItem_T *si1, *si2;
+ typval_T *tv1, *tv2;
char_u *p1, *p2;
- char_u *tofree1, *tofree2;
+ char_u *tofree1 = NULL, *tofree2 = NULL;
int res;
char_u numbuf1[NUMBUFLEN];
char_u numbuf2[NUMBUFLEN];
si1 = (sortItem_T *)s1;
si2 = (sortItem_T *)s2;
- p1 = tv2string(&si1->item->li_tv, &tofree1, numbuf1, 0);
- p2 = tv2string(&si2->item->li_tv, &tofree2, numbuf2, 0);
+ tv1 = &si1->item->li_tv;
+ tv2 = &si2->item->li_tv;
+ /* tv2string() puts quotes around a string and allocates memory. Don't do
+ * that for string variables. Use a single quote when comparing with a
+ * non-string to do what the docs promise. */
+ if (tv1->v_type == VAR_STRING)
+ {
+ if (tv2->v_type != VAR_STRING || item_compare_numeric)
+ p1 = (char_u *)"'";
+ else
+ p1 = tv1->vval.v_string;
+ }
+ else
+ p1 = tv2string(tv1, &tofree1, numbuf1, 0);
+ if (tv2->v_type == VAR_STRING)
+ {
+ if (tv1->v_type != VAR_STRING || item_compare_numeric)
+ p2 = (char_u *)"'";
+ else
+ p2 = tv2->vval.v_string;
+ }
+ else
+ p2 = tv2string(tv2, &tofree2, numbuf2, 0);
if (p1 == NULL)
p1 = (char_u *)"";
if (p2 == NULL)
@@ -17411,8 +17433,8 @@ item_compare(s1, s2)
res = n1 == n2 ? 0 : n1 > n2 ? 1 : -1;
}
- /* When the result would be zero, compare the pointers themselves. Makes
- * the sort stable. */
+ /* When the result would be zero, compare the item indexes. Makes the
+ * sort stable. */
if (res == 0 && !item_compare_keep_zero)
res = si1->idx > si2->idx ? 1 : -1;
diff --git a/src/version.c b/src/version.c
index 7126b8b9ed..93660b44b5 100644
--- a/src/version.c
+++ b/src/version.c
@@ -742,6 +742,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 411,
+/**/
410,
/**/
409,