From 506561c792225514c545fa0b5924801201c7f4a2 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 16 Mar 2021 09:20:45 +0200 Subject: [PATCH] cgen: fix a bug (deleting a map key while iterating on the same map) detected by `-d debug_realloc` --- vlib/v/gen/c/comptime.v | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vlib/v/gen/c/comptime.v b/vlib/v/gen/c/comptime.v index 7ba552c364..1b59babafe 100644 --- a/vlib/v/gen/c/comptime.v +++ b/vlib/v/gen/c/comptime.v @@ -405,11 +405,16 @@ fn (mut g Gen) comp_for(node ast.CompFor) { g.stmts(node.stmts) i++ g.writeln('}') + // + mut delete_keys := []string{} for key, _ in g.comptime_var_type_map { if key.starts_with(node.val_var) { - g.comptime_var_type_map.delete(key) + delete_keys << key } } + for key in delete_keys { + g.comptime_var_type_map.delete(key) + } } } else if node.kind == .fields { // TODO add fields