Skip to content

Commit

Permalink
Fuzz lib: Ignore out of memory errors, and allow up to 20 megs for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas authored and Vexu committed May 3, 2024
1 parent 333089c commit baef5b6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions test/fuzz/fuzz_lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ const Source = aro.Source;
const Preprocessor = aro.Preprocessor;
const Parser = aro.Parser;

var fixed_buffer_mem: [10 * 1024 * 1024]u8 = undefined;
var fixed_buffer_mem: [20 * 1024 * 1024]u8 = undefined;

export fn compile_c_buf(buf: [*]const u8, len: c_int) void {
compileSlice(buf[0..@intCast(len)]) catch unreachable;
compileSlice(buf[0..@intCast(len)]) catch |e| switch (e) {
error.FatalError,
error.OutOfMemory,
=> {},
else => unreachable,
};
}

fn compileSlice(buf: []const u8) !void {
Expand All @@ -31,10 +36,7 @@ fn compileSlice(buf: []const u8) !void {
const builtin = try comp.generateBuiltinMacros(.include_system_defines);
const user_source = try comp.addSourceFromBuffer("<STDIN>", buf);

processSource(&comp, builtin, user_source) catch |e| switch (e) {
error.FatalError => {},
else => |err| return err,
};
try processSource(&comp, builtin, user_source);
_ = comp.sources.swapRemove(user_source.path);
}

Expand Down

0 comments on commit baef5b6

Please sign in to comment.