diff options
author | Bart Schaefer <barts@users.sourceforge.net> | 2005-09-24 17:43:55 +0000 |
---|---|---|
committer | Bart Schaefer <barts@users.sourceforge.net> | 2005-09-24 17:43:55 +0000 |
commit | 8d6cd1dc94f985e98a794d7e8d9f23ebe0b6d7e6 (patch) | |
tree | 735af557068536b58823ce9a909373bfb6dac55d /Functions/Misc | |
parent | ad2bd42c858aa7236e7b7404806d16b5b0efb6ac (diff) | |
download | zsh-8d6cd1dc94f985e98a794d7e8d9f23ebe0b6d7e6.tar.gz zsh-8d6cd1dc94f985e98a794d7e8d9f23ebe0b6d7e6.tar.xz zsh-8d6cd1dc94f985e98a794d7e8d9f23ebe0b6d7e6.zip |
unposted: range-checking of numeric arguments in zargs
Diffstat (limited to 'Functions/Misc')
-rw-r--r-- | Functions/Misc/zargs | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/Functions/Misc/zargs b/Functions/Misc/zargs index 71360e4ca..58d84617e 100644 --- a/Functions/Misc/zargs +++ b/Functions/Misc/zargs @@ -31,6 +31,12 @@ # # BUGS: # +# In the interests of expediency, numeric options (max-procs, max-lines, +# etc.) are range-checked only when their values make a difference to the +# end result. Because of the way zsh handles variables in math context, +# it's possible to pass the name of a variable as the value of a numeric +# option, and the value of that variable becomes the value of the option. +# # "Killed by a signal" is determined by the usual shell rule that $? is # the signal number plus 128, so zargs can be fooled by a command that # explicitly exits with 129+. Also, zsh prior to 4.1.x returns 1 rather @@ -207,6 +213,11 @@ then fi n=${${n##-(n|-max-args(=|))}:-$[ARGC+c]} +if (( n <= 0 )) +then + print -u2 'zargs: value for max-args must be >= 1' + return 1 +fi if (( n > c )) then (( n -= c )) @@ -215,7 +226,26 @@ else return 1 fi +s=${${s##-(s|-max-chars(=|))}:-20480} +if (( s <= 0 )) +then + print -u2 'zargs: value for max-chars must be >= 1' + return 1 +fi + +l=${${${l##*-(l|L|-max-lines(=|))}[-1]}:-${${l[1]:+1}:-$ARGC}} +if (( l <= 0 )) +then + print -u2 'zargs: value for max-lines must be >= 1' + return 1 +fi + P=${${P##-(P|-max-procs(=|))}:-1} +if (( P < 0 )) +then + print -u2 'zargs: value for max-procs must be >= 0' + return 1 +fi if (( P != 1 && ARGC > 1 )) then @@ -230,9 +260,6 @@ then fi fi -s=${${s##-(s|-max-chars(=|))}:-20480} -l=${${${l##*-(l|L|-max-lines(=|))}[-1]}:-${${l[1]:+1}:-$ARGC}} - # Everything has to be in a subshell just in case of backgrounding jobs, # so that we don't unintentionally "wait" for jobs of the parent shell. ( |