wasm-linker: fix use of invalidated memory in populateErrorNameTable

This commit is contained in:
Techatrix
2023-09-08 00:03:23 +02:00
committed by Jakub Konka
parent 9126852ba9
commit b642bb92e5

View File

@@ -3005,7 +3005,6 @@ pub fn getErrorTableSymbol(wasm: *Wasm) !u32 {
fn populateErrorNameTable(wasm: *Wasm) !void {
const symbol_index = wasm.error_table_symbol orelse return;
const atom_index = wasm.symbol_atom.get(.{ .file = null, .index = symbol_index }).?;
const atom = wasm.getAtomPtr(atom_index);
// Rather than creating a symbol for each individual error name,
// we create a symbol for the entire region of error names. We then calculate
@@ -3030,6 +3029,8 @@ fn populateErrorNameTable(wasm: *Wasm) !void {
var addend: u32 = 0;
const mod = wasm.base.options.module.?;
for (mod.global_error_set.keys()) |error_name_nts| {
const atom = wasm.getAtomPtr(atom_index);
const error_name = mod.intern_pool.stringToSlice(error_name_nts);
const len = @as(u32, @intCast(error_name.len + 1)); // names are 0-termianted