authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2024-03-08 12:14:08-08:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2024-03-11 05:06:17-07:00
logb16890e6ddb451301f09029e3b0649168dc53918
tree914a504b5f52248209eae6bd4cec8fd4842a7846
parent8799f7466d68405d715bf567c3de9935b619fcf6

ErrorBundle: Fix potential writes to stale/freed memory


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

lib/std/zig/ErrorBundle.zig+6-2
......@@ -433,7 +433,9 @@ pub const Wip = struct {
433433 // The ensureUnusedCapacity call above guarantees this.
434434 const notes_start = wip.reserveNotes(@intCast(other_list.len)) catch unreachable;
435435 for (notes_start.., other_list) |note, message| {
436 wip.extra.items[note] = @intFromEnum(wip.addOtherMessage(other, message) catch unreachable);
436 // This line can cause `wip.extra.items` to be resized.
437 const note_index = @intFromEnum(wip.addOtherMessage(other, message) catch unreachable);
438 wip.extra.items[note] = note_index;
437439 }
438440 }
439441
......@@ -522,7 +524,8 @@ pub const Wip = struct {
522524 };
523525 const loc = std.zig.findLineColumn(source, span.main);
524526
525 eb.extra.items[note_i] = @intFromEnum(try eb.addErrorMessage(.{
527 // This line can cause `wip.extra.items` to be resized.
528 const note_index = @intFromEnum(try eb.addErrorMessage(.{
526529 .msg = try eb.addString(msg),
527530 .src_loc = try eb.addSourceLocation(.{
528531 .src_path = try eb.addString(src_path),
......@@ -538,6 +541,7 @@ pub const Wip = struct {
538541 }),
539542 .notes_len = 0, // TODO rework this function to be recursive
540543 }));
544 eb.extra.items[note_i] = note_index;
541545 }
542546 }
543547 }