Skip to content

Commit c77a748

Browse files
author
Andrés Pesate
committed
Added preconditions to subscript to avoid unwanted changes or crashes.
1 parent 912c21d commit c77a748

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

Array2D/Array2D.swift

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public struct Array2D<T> {
1919
return array[row*columns + column]
2020
}
2121
set {
22+
precondition(row < rows, "Row \(row) Index is out of range. Array<T>(columns: \(columns), rows:\(rows))")
23+
precondition(column < columns, "Column \(column) Index is out of range. Array<T>(columns: \(columns), rows:\(rows))")
24+
2225
array[row*columns + column] = newValue
2326
}
2427
}

0 commit comments

Comments
 (0)