fuzzing: fix off-by-one in limit count

This commit is contained in:
Andrew Kelley 2025-09-25 17:16:10 -07:00
parent 98253bc0ee
commit 2da8ec9865

View file

@ -512,7 +512,7 @@ const Fuzzer = struct {
self.corpus_pos = 0;
const rng = self.rng.random();
while (true) {
const m = while (true) {
const m = self.mutations.items[rng.uintLessThanBiased(usize, self.mutations.items.len)];
if (!m.mutate(
rng,
@ -524,8 +524,11 @@ const Fuzzer = struct {
inst.const_vals8.items,
inst.const_vals16.items,
)) continue;
break m;
};
self.run();
if (inst.isFresh()) {
@branchHint(.unlikely);
@ -569,9 +572,6 @@ const Fuzzer = struct {
);
self.corpus_dir_idx += 1;
}
break;
}
}
};
@ -618,7 +618,7 @@ export fn fuzzer_new_input(bytes: abi.Slice) void {
export fn fuzzer_main(limit_kind: abi.LimitKind, amount: u64) void {
switch (limit_kind) {
.forever => while (true) fuzzer.cycle(),
.iterations => for (0..amount -| 1) |_| fuzzer.cycle(),
.iterations => for (0..amount) |_| fuzzer.cycle(),
}
}