Skip to content

Commit

Permalink
move allocator logic in loop function for better stability in AFL
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoff-it committed Jul 25, 2024
1 parent a06b265 commit 4ac3bfe
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/fuzz/afl.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@ const mem = std.mem;
// std.debug.assert(toggle_me == false);
// }

var gpa_impl: std.heap.GeneralPurposeAllocator(.{}) = .{};
var arena_impl: std.heap.ArenaAllocator = .{
.child_allocator = undefined,
.state = .{},
};

export fn zig_fuzz_init() void {
const gpa = gpa_impl.allocator();
arena_impl.child_allocator = gpa;
}
export fn zig_fuzz_init() void {}

export fn zig_fuzz_test(buf: [*]u8, len: isize) void {
var gpa_impl: std.heap.GeneralPurposeAllocator(.{}) = .{};
defer std.debug.assert(gpa_impl.deinit() == .ok);

var arena_impl = std.heap.ArenaAllocator.init(gpa_impl.allocator());
defer arena_impl.deinit();

const arena = arena_impl.allocator();
_ = arena_impl.reset(.retain_capacity);

const src = buf[0..@intCast(len)];
var t = ctx;
Expand Down

0 comments on commit 4ac3bfe

Please sign in to comment.