Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zargs error with some combinations of arguments
- X-seq: zsh-workers 50497
- From: Alan Wagner-Krankel <awk@xxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: zsh-workers@xxxxxxx
- Subject: Re: zargs error with some combinations of arguments
- Date: Mon, 22 Aug 2022 23:39:32 -0500
- Archived-at: <https://zsh.org/workers/50497>
- In-reply-to: <CAH+w=7ZAMPN2sKbD1_Fg7eB0ZrqBHLYt3+8KrtFh8TEu24B=_w@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAGZNKjKKfA3yS1HRBTgij1DtU0EB4OVx9GxsQq6i1=rnBUfUug@mail.gmail.com> <CAH+w=7ZAMPN2sKbD1_Fg7eB0ZrqBHLYt3+8KrtFh8TEu24B=_w@mail.gmail.com>
I think we're both proposing basically the same change. It looks like
the format of my context diff hid the use of the calculated 'a' value
later in the code. Here's the diff listing from git:
diff --git a/Functions/Misc/zargs b/Functions/Misc/zargs
index 782d681..c7e96b8 100644
--- a/Functions/Misc/zargs
+++ b/Functions/Misc/zargs
@@ -194,7 +194,7 @@ else
return 1
fi
-local -i end c=0
+local -i end a c=0
if [[ $eof == -(e|-eof) ]]; then ((end=ARGC+1))
elif (( $#eof )); then end=$argv[(i)${eof##-(e|-eof=)}]
else end=$argv[(i)--]
@@ -265,6 +265,13 @@ then
return 1
fi
+(( a = s - ${#:-"$command "} ))
+if (( a <= 0 ))
+then
+ print -u2 'zargs: value for max-chars must be >= command length'
+ return 1
+fi
+
l=${${${l##*-(l|L|-max-lines(=|))}[-1]}:-${${l[1]:+1}:-$ARGC}}
if (( l <= 0 ))
then
@@ -305,7 +312,7 @@ do
repeat $P
do
((ARGC)) || break
- for (( end=l; end && ${(c)#argv[1,end]} > s; end/=2 )) { }
+ for (( end=l; end && ${(c)#argv[1,end]} > a; end/=2 )) { }
(( end > n && ( end = n ) ))
args=( "${(@)argv[1,end]}" )
shift $((end > ARGC ? ARGC : end))
In this line:
(( a = s - ${#:-"$command "} ))
's' is the max size of the total command line. The calculated value
'a' represents the maximum number of characters that can be used for
arguments to the command. It's stored in a variable to avoid
recalculating it each time in the primary nested loop.
The 'command' variable is an array, and we also need a space for the
separator between the command and the parameters. ${#:-"$command "}
was my (possibly too cute) way of calculating the total length of the
command plus the space. This should give the same result:
(( a = s - ${(c)#command} - 1 ))
The error message after the 'a <= 0' test is only going to occur
with some edge cases and nonsensical parameters, e.g.:
zargs -s 10 -- a b c -- somelongcmd
It's not really needed. If the command is too large, the 'cannot fit
single argument within size limit' error message will do the job.
Thanks for looking into this,
Awk
Messages sorted by:
Reverse Date,
Date,
Thread,
Author