Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

Commit

Permalink
DirectArena failed to memcpy on realloc
Browse files Browse the repository at this point in the history
  • Loading branch information
andersfr committed Aug 19, 2019
1 parent e7ced70 commit f4f7cbe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion zig/direct_arena.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub const DirectArena = struct {
if (new_size == 0)
return (([*]u8)(undefined))[0..0];

std.debug.assert(old_mem_unaligned.len == 0);
std.debug.assert(new_size <= std.mem.page_size - @sizeOf(DirectArena));

const arena = @fieldParentPtr(DirectArena, "allocator", allocator).next;
Expand All @@ -59,6 +58,8 @@ pub const DirectArena = struct {
if(arena.offset + new_size <= std.mem.page_size) {
const slice = @intToPtr([*]u8, @ptrToInt(arena) + arena.offset)[0..new_size];
arena.offset += new_size;
if(old_mem_unaligned.len > 0)
@memcpy(slice.ptr, old_mem_unaligned.ptr, old_mem_unaligned.len);
return slice;
}

Expand All @@ -78,6 +79,8 @@ pub const DirectArena = struct {
if(next.offset + new_size <= std.mem.page_size) {
const slice = @intToPtr([*]u8, @ptrToInt(next) + next.offset)[0..new_size];
next.offset += new_size;
if(old_mem_unaligned.len > 0)
@memcpy(slice.ptr, old_mem_unaligned.ptr, old_mem_unaligned.len);
return slice;
}

Expand Down
2 changes: 1 addition & 1 deletion zig/zig_lexer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ pub const Lexer = struct {
},
'#' => {
if(self.index == 1 and self.peek == '!') {
self.getc();
while(self.peek != '\n' and self.peek != -1) self.getc();
return Id.ShebangLine;
}
return Id.Invalid;
},
'%' => {
if(self.peek == '=') {
Expand Down
2 changes: 1 addition & 1 deletion zig/zig_parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ pub const Parser = struct {
if (token.id == .Eof)
break;
}
const shebang = if (self.tokens.items[1].id == .ShebangLine) @intCast(usize, 1) else @intCast(usize, 0);
const shebang = if (self.tokens.items[1].id == .ShebangLine) usize(1) else usize(0);
var i: usize = shebang + 1;
// If file starts with a DocComment this is considered a RootComment
while (i < self.tokens.len) : (i += 1) {
Expand Down

0 comments on commit f4f7cbe

Please sign in to comment.