Validate table.remove pos.

This commit is contained in:
Enyby
2019-11-03 16:08:01 +02:00
parent 9a20aa8077
commit e120008f9b

View File

@@ -126,7 +126,13 @@ public class TableLib extends TwoArgFunction {
// "remove" (table [, pos]) -> removed-ele // "remove" (table [, pos]) -> removed-ele
static class remove extends VarArgFunction { static class remove extends VarArgFunction {
public Varargs invoke(Varargs args) { public Varargs invoke(Varargs args) {
return args.checktable(1).remove(args.optint(2, 0)); LuaTable table = args.checktable(1);
int size = table.length();
int pos = args.optint(2, size);
if (pos != size && (pos < 1 || pos > size + 1)) {
argerror(2, "position out of bounds: " + pos + " not between 1 and " + (size + 1));
}
return table.remove(pos);
} }
} }