diff options
| author | Baitinq <[email protected]> | 2025-07-26 19:46:00 +0200 |
|---|---|---|
| committer | Baitinq <[email protected]> | 2025-07-26 19:46:00 +0200 |
| commit | cc0584d581a5f9a94b949fee51c694feca77723a (patch) | |
| tree | cf37f2abaf6d139b87184983809df0faf9d5b906 /std | |
| parent | Parser: Fix memory leak (diff) | |
| download | pry-lang-cc0584d581a5f9a94b949fee51c694feca77723a.tar.gz pry-lang-cc0584d581a5f9a94b949fee51c694feca77723a.tar.bz2 pry-lang-cc0584d581a5f9a94b949fee51c694feca77723a.zip | |
std: mem: Assert arena allocator is not overflown
Diffstat (limited to 'std')
| -rw-r--r-- | std/mem.pry | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/std/mem.pry b/std/mem.pry index 75f3d1d..52de4d5 100644 --- a/std/mem.pry +++ b/std/mem.pry @@ -7,12 +7,14 @@ import "!stdlib.pry"; let arena = struct { buf: *void, offset: i64, + size: i64, }; let arena_init = (size: i64) => *arena { let a = cast(*arena, calloc(1, sizeof(arena))); (*a).buf = calloc(1, size); (*a).offset = 0; + (*a).size = size; return a; }; @@ -23,6 +25,7 @@ let arena_free = (a: *arena) => void { }; let arena_alloc = (a: *arena, size: i64) => *void { + assert((*a).offset + size < (*a).size); let old_offset = (*a).offset; (*a).offset = (*a).offset + size; return cast(*void, cast(*i8, (*a).buf) + cast(*i8, old_offset)); |