diff --git a/vlib/gg/image.v b/vlib/gg/image.v index 3f2083c8c1..2ac084b4b4 100644 --- a/vlib/gg/image.v +++ b/vlib/gg/image.v @@ -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) { diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 6b8a4ae98c..f96f277d87 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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() { diff --git a/vlib/v/checker/tests/unsafe_fixed_array_assign.out b/vlib/v/checker/tests/unsafe_fixed_array_assign.out new file mode 100644 index 0000000000..fae8c95983 --- /dev/null +++ b/vlib/v/checker/tests/unsafe_fixed_array_assign.out @@ -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) diff --git a/vlib/v/checker/tests/unsafe_fixed_array_assign.vv b/vlib/v/checker/tests/unsafe_fixed_array_assign.vv new file mode 100644 index 0000000000..38defbd6f8 --- /dev/null +++ b/vlib/v/checker/tests/unsafe_fixed_array_assign.vv @@ -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)