Skip to content

Commit c33fda1

Browse files
authored
Add assertion and comment that ColumnMap init() function will accept only correct ColumnIndex values. (#7672)
1 parent ec26965 commit c33fda1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

beacon_chain/spec/column_map.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ func excl*(a: var ColumnMap, column: ColumnIndex) =
4343
a.data[index].clearBit(offset)
4444

4545
func init*(t: typedesc[ColumnMap], columns: openArray[ColumnIndex]): ColumnMap =
46+
## NOTE: `columns` array's content should be checked before running this
47+
## function. Function will assert if `ColumnIndex >= NUMBER_OF_COLUMNS`.
4648
var res: ColumnMap
4749
for column in columns:
50+
if uint64(column) >= NUMBER_OF_COLUMNS:
51+
raiseAssert "Incorrect column index, " & $uint64(column)
4852
let (index, offset) = column.getPos()
4953
res.data[index].setBit(offset)
5054
res

0 commit comments

Comments
 (0)