zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit c4a54377e3f07bbd2f9c54c1962c7941792c2c1f (tree)
parent 751ab72a82a0edc4c5c129c6675a33d3cd57fa73
Author: Marc Tiehuis <marctiehuis@gmail.com>
Date:   Wed, 20 Sep 2017 01:47:41 +1200

Stop debug allocator ever panicking (#492)


Diffstat:
Mstd/debug.zig | 5+++++
1 file changed, 5 insertions(+), 0 deletions(-)

diff --git a/std/debug.zig b/std/debug.zig @@ -957,12 +957,17 @@ pub var global_allocator = mem.Allocator { var some_mem: [100 * 1024]u8 = undefined; var some_mem_index: usize = 0; +error OutOfMemory; + fn globalAlloc(self: &mem.Allocator, n: usize, alignment: usize) -> %[]u8 { const addr = @ptrToInt(&some_mem[some_mem_index]); const rem = @rem(addr, alignment); const march_forward_bytes = if (rem == 0) 0 else (alignment - rem); const adjusted_index = some_mem_index + march_forward_bytes; const end_index = adjusted_index + n; + if (end_index > some_mem.len) { + return error.OutOfMemory; + } const result = some_mem[adjusted_index .. end_index]; some_mem_index = end_index; return result;