Skip to content

Commit 2a82157

Browse files
Fix alist.Cut(0), list.Cut(0), and list.len = <0 bugs (#2489)
1 parent c88c42e commit 2a82157

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

OpenDreamRuntime/Objects/Types/DreamAssocList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public int GetLength() {
4343
}
4444

4545
public void Cut(int start = 1, int end = 0) {
46-
if (start != 1) {
46+
if (start != 1 && start != 0) {
4747
throw new Exception($"Cut() was called with non-default start value of {start}.");
4848
}
4949

OpenDreamRuntime/Objects/Types/DreamList.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ public virtual int FindValue(DreamValue value, int start = 1, int end = 0) {
228228
}
229229

230230
public virtual void Cut(int start = 1, int end = 0) {
231+
start = start switch {
232+
< 0 => throw new ArgumentOutOfRangeException(nameof(start), start, "Parameter start is less than zero."),
233+
0 => 1,
234+
_ => start
235+
};
231236
if (end == 0 || end > (_values.Count + 1)) end = _values.Count + 1;
232237

233238
if (_associativeValues != null) {
@@ -263,6 +268,7 @@ public void Resize(int size) {
263268
} else {
264269
if (size < 0) {
265270
DreamManager.OptionalException<InvalidOperationException>(DMCompiler.Compiler.WarningCode.ListNegativeSizeException, "Setting a list size to a negative value is invalid");
271+
size = 0;
266272
}
267273

268274
Cut(size + 1);

0 commit comments

Comments
 (0)