fix(git-bulk): fix a bad integer expression (#1198)

Fix a logic error inside the `allowedargcount()` function. This function
may be called with one or two arguments. However, no default values are
assigned to `$1` and `$2` that are used inside a numerical comparison.
Therefore, when using a bad number of arguments for the following lines:

```
listall|purge) allowedargcount 1;;
addcurrent|removeworkspace) allowedargcount 2;;
```

Then, we would get the error `[: : integer expression expected`. To fix
this, we assign the 0 default value to `$1` and `$2`, such that we
trigger the error message destined to the user without any integer error
when there is a bad number of argument and that the function is called
with only 1 argument instead of 2.
This commit is contained in:
Pierre Ayoub 2025-02-20 08:41:42 +01:00 committed by GitHub
parent df53711fc7
commit 82cc37d0f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -129,7 +129,7 @@ function wsnameToCurrent () {
# helper to check number of arguments.
function allowedargcount () {
if [ "$paramcount" -ne "$1" ] && [ "$paramcount" -ne "$2" ]; then
if [ "$paramcount" -ne "${1:-0}" ] && [ "$paramcount" -ne "${2:-0}" ]; then
echo 1>&2 "error: wrong number of arguments" && usage;
exit 1;
fi