diff src/eval.c @ 8344:2aa24f702b8d v7.4.1464

commit https://github.com/vim/vim/commit/5131c144feb046c5e2b72e6c172159d80ce06b3c Author: Bram Moolenaar <Bram@vim.org> Date: Mon Feb 29 22:05:26 2016 +0100 patch 7.4.1464 Problem: When the argument of sort() is zero or empty it fails. Solution: Make zero work as documented. (suggested by Yasuhiro Matsumoto)
author Christian Brabandt <cb@256bit.org>
date Mon, 29 Feb 2016 22:15:05 +0100
parents 3e54b31d50c7
children e70fa2e110ec
line wrap: on
line diff
--- a/src/eval.c
+++ b/src/eval.c
@@ -19195,11 +19195,21 @@ do_sort_uniq(typval_T *argvars, typval_T
 		    goto theend;	/* type error; errmsg already given */
 		if (i == 1)
 		    info.item_compare_ic = TRUE;
-		else
+		else if (argvars[1].v_type != VAR_NUMBER)
 		    info.item_compare_func = get_tv_string(&argvars[1]);
+		else if (i != 0)
+		{
+		    EMSG(_(e_invarg));
+		    goto theend;
+		}
 		if (info.item_compare_func != NULL)
 		{
-		    if (STRCMP(info.item_compare_func, "n") == 0)
+		    if (*info.item_compare_func == NUL)
+		    {
+			/* empty string means default sort */
+			info.item_compare_func = NULL;
+		    }
+		    else if (STRCMP(info.item_compare_func, "n") == 0)
 		    {
 			info.item_compare_func = NULL;
 			info.item_compare_numeric = TRUE;