1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: add fixed array bounds checking for non-literal index (#8832)

This commit is contained in:
Nick Treleaven
2021-02-22 12:54:24 +00:00
committed by GitHub
parent 41a3b115a1
commit 15daeaeafa
9 changed files with 56 additions and 4 deletions

View File

@ -274,3 +274,14 @@ pub fn is_atty(fd int) int {
return C.isatty(fd)
}
}
[inline]
fn v_fixed_index(i int, len int) int {
$if !no_bounds_checking ? {
if i < 0 || i >= len {
s := 'fixed array index out of range (index: $i, len: $len)'
panic(s)
}
}
return i
}