mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: prohibit fixed array to fixed array assignment where elem_typ is a pointer (#10775)
This commit is contained in:
parent
6e942bf4c2
commit
7c0be629ab
@ -222,7 +222,8 @@ pub fn (mut ctx Context) new_streaming_image(w int, h int, channels int) int {
|
||||
// update_pixel_data is a helper for working with image streams (i.e. images,
|
||||
// that are updated dynamically by the CPU on each frame)
|
||||
pub fn (mut ctx Context) update_pixel_data(cached_image_idx int, buf &byte) {
|
||||
ctx.get_cached_image_by_idx(cached_image_idx).update_pixel_data(buf)
|
||||
mut image := ctx.get_cached_image_by_idx(cached_image_idx)
|
||||
image.update_pixel_data(buf)
|
||||
}
|
||||
|
||||
pub fn (mut img Image) update_pixel_data(buf &byte) {
|
||||
|
@ -3909,6 +3909,16 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
||||
c.error('use `array2 $node.op.str() array1.clone()` instead of `array2 $node.op.str() array1` (or use `unsafe`)',
|
||||
node.pos)
|
||||
}
|
||||
if left_sym.kind == .array_fixed && !c.inside_unsafe && node.op in [.assign, .decl_assign]
|
||||
&& right_sym.kind == .array_fixed && (left is ast.Ident && !left.is_blank_ident())
|
||||
&& right is ast.Ident {
|
||||
if right_sym.info is ast.ArrayFixed {
|
||||
if right_sym.info.elem_type.is_ptr() {
|
||||
c.error('assignment from one fixed array to another with a pointer element type is prohibited outside of `unsafe`',
|
||||
node.pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
if left_sym.kind == .map && node.op in [.assign, .decl_assign] && right_sym.kind == .map
|
||||
&& ((right is ast.Ident && right.is_auto_deref_var())
|
||||
|| !right_type.is_ptr()) && !left.is_blank_ident() && right.is_lvalue() {
|
||||
|
7
vlib/v/checker/tests/unsafe_fixed_array_assign.out
Normal file
7
vlib/v/checker/tests/unsafe_fixed_array_assign.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/unsafe_fixed_array_assign.vv:8:7: error: assignment from one fixed array to another with a pointer element type is prohibited outside of `unsafe`
|
||||
6 | mut box := Box { num: 10 }
|
||||
7 | a := [&box]!
|
||||
8 | mut b := a
|
||||
| ~~
|
||||
9 | b[0].num = 0
|
||||
10 | println(a)
|
10
vlib/v/checker/tests/unsafe_fixed_array_assign.vv
Normal file
10
vlib/v/checker/tests/unsafe_fixed_array_assign.vv
Normal file
@ -0,0 +1,10 @@
|
||||
struct Box {
|
||||
mut:
|
||||
num int
|
||||
}
|
||||
|
||||
mut box := Box { num: 10 }
|
||||
a := [&box]!
|
||||
mut b := a
|
||||
b[0].num = 0
|
||||
println(a)
|
Loading…
Reference in New Issue
Block a user