mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
compiler: prevent accessing negative index of arrays
This commit is contained in:
parent
38db845378
commit
14c2319dcc
@ -1963,11 +1963,15 @@ fn (p mut Parser) index_expr(typ_ string, fn_ph int) string {
|
||||
}
|
||||
// expression inside [ ]
|
||||
if is_arr {
|
||||
index_pos := p.cgen.cur_line.len
|
||||
T := p.table.find_type(p.expression())
|
||||
// Allows only i8-64 and u8-64 to be used when accessing an array
|
||||
if T.parent != 'int' && T.parent != 'u32' {
|
||||
p.check_types(T.name, 'int')
|
||||
}
|
||||
if p.cgen.cur_line.right(index_pos).replace(' ', '').int() < 0 {
|
||||
p.error('cannot access negative array index')
|
||||
}
|
||||
}
|
||||
else {
|
||||
T := p.table.find_type(p.expression())
|
||||
|
Loading…
Reference in New Issue
Block a user