1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-01-01 05:16:05 +01:00

38971: Start using the new arrlen_ge() / arrlen_le() helpers.

This commit is contained in:
Daniel Shahaf 2016-07-30 10:50:48 +00:00
parent 1a368bf31f
commit f9b1703511
7 changed files with 16 additions and 12 deletions

View file

@ -1,5 +1,9 @@
2016-08-01 Daniel Shahaf <d.s@daniel.shahaf.name>
* 38971: Src/Modules/terminfo.c, Src/Modules/zutil.c,
Src/builtin.c, Src/params.c, Src/prompt.c, Src/utils.c: Start
using the new arrlen_ge() / arrlen_le() helpers.
* 38973: Src/params.c, Src/subst.c, Src/utils.c: Optimize
indexing array parameters.

View file

@ -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;
}

View file

@ -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];

View file

@ -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;

View file

@ -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;
}

View file

@ -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':

View file

@ -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));