Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH 2/2] Start using the new arrlen_ge() / arrlen_le() helpers.



---
 Src/Modules/terminfo.c | 2 +-
 Src/Modules/zutil.c    | 4 ++--
 Src/builtin.c          | 6 +++---
 Src/params.c           | 4 ++--
 Src/prompt.c           | 6 +++---
 Src/utils.c            | 2 +-
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/Src/Modules/terminfo.c b/Src/Modules/terminfo.c
index e0439af..bbd3258 100644
--- a/Src/Modules/terminfo.c
+++ b/Src/Modules/terminfo.c
@@ -99,7 +99,7 @@ bin_echoti(char *name, char **argv, UNUSED(Options ops), UNUSED(int func))
 	return 1;
     }
     /* check that the number of arguments provided is not too high */
-    if (arrlen(argv) > 9) {
+    if (arrlen_gt(argv, 9)) {
         zwarnnam(name, "too many arguments");
         return 1;
     }
diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c
index 477575c..d95c0c2 100644
--- a/Src/Modules/zutil.c
+++ b/Src/Modules/zutil.c
@@ -472,7 +472,7 @@ bin_zstyle(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
 	Patprog prog;
 	char *pat;
 
-	if (arrlen(args) < 2) {
+	if (arrlen_lt(args, 2)) {
 	    zwarnnam(nam, "not enough arguments");
 	    return 1;
 	}
@@ -491,7 +491,7 @@ bin_zstyle(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
 	Style s;
 	char *context, *stylename;
 
-	switch (arrlen(args)) {
+	switch (arrlen_ge(args, 3) ? 3 : arrlen(args)) {
 	case 2:
 	    context = args[0];
 	    stylename = args[1];
diff --git a/Src/builtin.c b/Src/builtin.c
index bfb9e69..fb14b2e 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3406,7 +3406,7 @@ bin_unset(char *name, char **argv, Options ops, int func)
 		    } else {
 			/* start is after the element for reverse index */
 			int start = vbuf.start - !!(vbuf.flags & VALFLAG_INV);
-			if (start < arrlen(vbuf.pm->u.arr)) {
+			if (arrlen_gt(vbuf.pm->u.arr, start)) {
 			    char *arr[2];
 			    arr[0] = "";
 			    arr[1] = 0;
@@ -5026,7 +5026,7 @@ bin_shift(char *name, char **argv, Options ops, UNUSED(int func))
     if (*argv) {
         for (; *argv; argv++)
             if ((s = getaparam(*argv))) {
-                if (num > arrlen(s)) {
+                if (arrlen_lt(s, num)) {
 		    zwarnnam(name, "shift count must be <= $#");
 		    ret++;
 		    continue;
@@ -5095,7 +5095,7 @@ bin_getopts(UNUSED(char *name), char **argv, UNUSED(Options ops), UNUSED(int fun
 	zoptind = 1;
 	optcind = 0;
     }
-    if(zoptind > arrlen(args))
+    if (arrlen_lt(args, zoptind))
 	/* no more options */
 	return 1;
 
diff --git a/Src/params.c b/Src/params.c
index 33f177e..0eda784 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2225,13 +2225,13 @@ getarrvalue(Value v)
 	v->start += arrlen(s);
     if (v->end < 0)
 	v->end += arrlen(s) + 1;
-    if (v->start > arrlen(s) || v->start < 0)
+    if (arrlen_lt(s, v->start) || v->start < 0)
 	s = arrdup(nular);
     else
 	s = arrdup(s + v->start);
     if (v->end <= v->start)
 	s[0] = NULL;
-    else if (v->end - v->start <= arrlen(s))
+    else if (arrlen_ge(s, v->end - v->start))
 	s[v->end - v->start] = NULL;
     return s;
 }
diff --git a/Src/prompt.c b/Src/prompt.c
index bb27453..d4f3898 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -395,11 +395,11 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 			test = 1;
 		    break;
 		case 'v':
-		    if (arrlen(psvar) >= arg)
+		    if (arrlen_ge(psvar, arg))
 			test = 1;
 		    break;
 		case 'V':
-		    if (arrlen(psvar) >= arg) {
+		    if (arrlen_ge(psvar, arg)) {
 			if (*psvar[(arg ? arg : 1) - 1])
 			    test = 1;
 		    }
@@ -736,7 +736,7 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 		    arg = 1;
 		else if (arg < 0)
 		    arg += arrlen(psvar) + 1;
-		if (arg > 0 && arrlen(psvar) >= arg)
+		if (arg > 0 && arrlen_ge(psvar, arg))
 		    stradd(psvar[arg - 1]);
 		break;
 	    case 'E':
diff --git a/Src/utils.c b/Src/utils.c
index 95da960..0a5954f 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -1157,7 +1157,7 @@ finddir(char *s)
     scanhashtable(nameddirtab, 0, 0, 0, finddir_scan, 0);
 
     ares = subst_string_by_hook("zsh_directory_name", "d", finddir_full);
-    if (ares && arrlen(ares) >= 2 &&
+    if (ares && arrlen_ge(ares, 2) &&
 	(len = (int)zstrtol(ares[1], NULL, 10)) > finddir_best) {
 	/* better duplicate this string since it's come from REPLY */
 	finddir_last = (Nameddir)hcalloc(sizeof(struct nameddir));



Messages sorted by: Reverse Date, Date, Thread, Author