diff --git a/fuzz/c/fuzzlib/fuzzlib.c b/fuzz/c/fuzzlib/fuzzlib.cc similarity index 87% rename from fuzz/c/fuzzlib/fuzzlib.c rename to fuzz/c/fuzzlib/fuzzlib.cc index bc40a248..6b7aaa48 100644 --- a/fuzz/c/fuzzlib/fuzzlib.c +++ b/fuzz/c/fuzzlib/fuzzlib.cc @@ -28,11 +28,7 @@ void intentional_segfault() { void fuzz(wuffs_base__reader1 src_reader, uint32_t hash); -#ifdef __cplusplus -extern "C" -#endif - int - LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { // Hash input as per https://en.wikipedia.org/wiki/Jenkins_hash_function size_t i = 0; uint32_t hash = 0; @@ -45,8 +41,11 @@ extern "C" hash ^= hash >> 11; hash += hash << 15; - wuffs_base__buf1 src = { - .ptr = (uint8_t*)(data), .len = size, .wi = size, .closed = true}; + wuffs_base__buf1 src = {.ptr = (uint8_t*)(data), + .len = size, + .wi = size, + .ri = 0, + .closed = true}; fuzz((wuffs_base__reader1){.buf = &src}, hash); return 0; } @@ -85,7 +84,7 @@ int main(int argc, char** argv) { return 1; } - int fuzz = LLVMFuzzerTestOneInput(data, n); + int fuzz = LLVMFuzzerTestOneInput((const uint8_t*)(data), n); if (fuzz) { return fuzz; } diff --git a/fuzz/c/std/gif.c b/fuzz/c/std/gif.cc similarity index 96% rename from fuzz/c/std/gif.c rename to fuzz/c/std/gif.cc index 0260cea5..12c9dc61 100644 --- a/fuzz/c/std/gif.c +++ b/fuzz/c/std/gif.cc @@ -23,7 +23,8 @@ such as https://github.com/google/oss-fuzz calling LLVMFuzzerTestOneInput. When working on the fuzz implementation, or as a sanity check, defining WUFFS_CONFIG__FUZZLIB_MAIN will let you manually run fuzz over a set of files: -gcc -DWUFFS_CONFIG__FUZZLIB_MAIN gif.c && ./a.out ../../../test/testdata/*.gif +g++ -DWUFFS_CONFIG__FUZZLIB_MAIN gif.cc +./a.out ../../../test/testdata/*.gif rm -f ./a.out It should print "PASS", amongst other information, and exit(0). @@ -35,7 +36,7 @@ It should print "PASS", amongst other information, and exit(0). // relative includes, you can use the script/inline-c-relative-includes.go // program to generate a stand-alone C file. #include "../../../gen/c/std/gif.c" -#include "../fuzzlib/fuzzlib.c" +#include "../fuzzlib/fuzzlib.cc" void fuzz(wuffs_base__reader1 src_reader, uint32_t hash) { void* pixbuf = NULL; diff --git a/fuzz/c/std/zlib.c b/fuzz/c/std/zlib.cc similarity index 95% rename from fuzz/c/std/zlib.c rename to fuzz/c/std/zlib.cc index 639d10c2..c9b53eea 100644 --- a/fuzz/c/std/zlib.c +++ b/fuzz/c/std/zlib.cc @@ -23,7 +23,8 @@ such as https://github.com/google/oss-fuzz calling LLVMFuzzerTestOneInput. When working on the fuzz implementation, or as a sanity check, defining WUFFS_CONFIG__FUZZLIB_MAIN will let you manually run fuzz over a set of files: -gcc -DWUFFS_CONFIG__FUZZLIB_MAIN zlib.c && ./a.out ../../../test/testdata/*.zlib +g++ -DWUFFS_CONFIG__FUZZLIB_MAIN zlib.cc +./a.out ../../../test/testdata/*.zlib rm -f ./a.out It should print "PASS", amongst other information, and exit(0). @@ -36,7 +37,7 @@ It should print "PASS", amongst other information, and exit(0). // program to generate a stand-alone C file. #include "../../../gen/c/std/deflate.c" #include "../../../gen/c/std/zlib.c" -#include "../fuzzlib/fuzzlib.c" +#include "../fuzzlib/fuzzlib.cc" void fuzz(wuffs_base__reader1 src_reader, uint32_t hash) { wuffs_zlib__status s;