authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-27 20:31:54+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-27 20:31:54+03:00
logbda7993bebf6c13d1c4f98269c80a2463f99e659
treee94414505f1baf6be87060b46ce798d5cac62e98
parentd15bbebe2e6b8fcbfcd730a6c0d1be621b27045d

Sema: fix error set memory unsafety

All error names are supposed to be owned by Module.

1 files changed, 5 insertions(+), 6 deletions(-)

src/Sema.zig+5-6
...@@ -2317,8 +2317,8 @@ fn zirErrorSetDecl(...@@ -2317,8 +2317,8 @@ fn zirErrorSetDecl(
2317 const extra_index_end = extra_index + (extra.data.fields_len * 2);2317 const extra_index_end = extra_index + (extra.data.fields_len * 2);
2318 while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string2318 while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string
2319 const str_index = sema.code.extra[extra_index];2319 const str_index = sema.code.extra[extra_index];
2320 const name = try new_decl_arena_allocator.dupe(u8, sema.code.nullTerminatedString(str_index));2320 const kv = try sema.mod.getErrorValue(sema.code.nullTerminatedString(str_index));
2321 const result = names.getOrPutAssumeCapacity(name);2321 const result = names.getOrPutAssumeCapacity(kv.key);
2322 assert(!result.found_existing); // verified in AstGen2322 assert(!result.found_existing); // verified in AstGen
2323 }2323 }
23242324
...@@ -13113,11 +13113,10 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -13113,11 +13113,10 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
13113 // TODO use reflection instead of magic numbers here13113 // TODO use reflection instead of magic numbers here
13114 // error_set: type,13114 // error_set: type,
13115 const name_val = struct_val[0];13115 const name_val = struct_val[0];
13116 const name_str = try name_val.toAllocatedBytes(Type.initTag(.const_slice_u8), sema.arena, target);
1311613117
13117 names.putAssumeCapacityNoClobber(13118 const kv = try sema.mod.getErrorValue(name_str);
13118 try name_val.toAllocatedBytes(Type.initTag(.const_slice_u8), sema.arena, target),13119 names.putAssumeCapacityNoClobber(kv.key, {});
13119 {},
13120 );
13121 }13120 }
1312213121
13123 // names must be sorted13122 // names must be sorted