Full example code to serve as a companion to An Intro to Zig's checkAllAllocationFailures
Clone this repository and run the following commands (requires latest master version of Zig):
zig build test1
: Run the initial test code. This should pass.zig build test2
: Run the test code transformed to be compatible withcheckAllAllocationFailures
, but without actually usingcheckAllAllocationFailures
yet. This should pass.zig build test3
: Run the test code withcheckAllAllocationFailures
. This should fail due to a leak duringfail index 1/5
.zig build test4
: Run the test code withcheckAllAllocationFailures
with theerrdefer
fixes in place. This should now pass.zig build test4 -Dcheck-allocation-failures=false
: Runtest4
but withoutcheckAllAllocationFailures
. This should pass.zig build caveat
: Run a test case that will triggererror.NondeterministicMemoryUsage
duringcheckAllAllocationFailures
.zig build fuzz
: Build an executable that will work withafl-fuzz
. Requires AFL++ to be installed. See Fuzzing Zig Code Using AFL++ for more info.- After building, use
afl-fuzz -i test/fuzz-inputs -o test/fuzz-outputs -- ./zig-out/bin/fuzz
to start fuzz testing. No crashes should be found.
- After building, use