Skip to content

Commit

Permalink
Compilation: use an errdefer compile error for documentation instead …
Browse files Browse the repository at this point in the history
…of a comment
  • Loading branch information
ehaas committed Oct 9, 2023
1 parent 18451bd commit ca2b917
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1084,10 +1084,8 @@ pub fn addSourceFromOwnedBuffer(comp: *Compilation, buf: []u8, path: []const u8,
const splice_locs = try splice_list.toOwnedSlice();
errdefer comp.gpa.free(splice_locs);

// Important: do not perform any possibly-failing operations in this function after this realloc.
// Otherwise errdefers in callers will possibly free the realloced slice using the original len
// instead of the new
if (i != contents.len) contents = try comp.gpa.realloc(contents, i);
errdefer @compileError("errdefers in callers would possibly free the realloced slice using the original len");

var source = Source{
.id = source_id,
Expand Down

0 comments on commit ca2b917

Please sign in to comment.