Fix parsing of INT_MIN %arg

Fixes #4601
This commit is contained in:
Maxime Coste 2022-05-05 20:04:51 +10:00
parent d2f9bc8d80
commit 56c3ab4ff8
5 changed files with 11 additions and 3 deletions

View File

@ -382,10 +382,10 @@ void expand_token(Token&& token, const Context& context, const ShellContext& she
return set_target(params);
}
const int arg = str_to_int(content)-1;
if (arg < 0)
const int arg = str_to_int(content);
if (arg < 1)
throw runtime_error("invalid argument index");
return set_target(arg < params.size() ? params[arg] : String{});
return set_target(arg <= params.size() ? params[arg-1] : String{});
}
case Token::Type::FileExpand:
return set_target(read_file(content));

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@
ok

View File

@ -0,0 +1,5 @@
try %{
nop %arg{-2147483648}
} catch %{
exec iok<esc>
}