From 2a97a1ad29bd384e5471a50ec307fbb40d66ceeb Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 3 May 2018 08:15:29 +1000 Subject: [PATCH] Edit fuzz' .c files to be C, not C++ --- fuzz/c/fuzzlib/fuzzlib.c | 10 +++++++++- fuzz/c/std/README.md | 6 +++--- fuzz/c/std/gif_fuzzer.c | 4 ++-- fuzz/c/std/zlib_fuzzer.c | 4 ++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/fuzz/c/fuzzlib/fuzzlib.c b/fuzz/c/fuzzlib/fuzzlib.c index 96d20eeb..61e43c9d 100644 --- a/fuzz/c/fuzzlib/fuzzlib.c +++ b/fuzz/c/fuzzlib/fuzzlib.c @@ -28,7 +28,11 @@ void intentional_segfault() { void fuzz(wuffs_base__io_reader src_reader, uint32_t hash); -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { +#ifdef __cplusplus +extern "C" { +#endif + +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; @@ -50,6 +54,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { return 0; } +#ifdef __cplusplus +} // extern "C" +#endif + #ifdef WUFFS_CONFIG__FUZZLIB_MAIN #include diff --git a/fuzz/c/std/README.md b/fuzz/c/std/README.md index eb0481f0..b179172f 100644 --- a/fuzz/c/std/README.md +++ b/fuzz/c/std/README.md @@ -1,5 +1,5 @@ This directory contains multiple programs to fuzz Wuffs' implementations of -various codecs. For example, `gif_fuzzer.cc` is a program to fuzz Wuffs' GIF +various codecs. For example, `gif_fuzzer.c` is a program to fuzz Wuffs' GIF implementation. They are typically run indirectly, by a fuzzing framework such as @@ -9,5 +9,5 @@ directory's code. When working on these files, it is possible to run them directly on an explicit test suite, in order to speed up the edit-compile-run cycle. Look for -`WUFFS_CONFIG__FUZZLIB_MAIN` in the C++ code for more details, and in -`seed_corpora.txt` for suggested test data. +`WUFFS_CONFIG__FUZZLIB_MAIN` for more details, and in `seed_corpora.txt` for +suggested test data. diff --git a/fuzz/c/std/gif_fuzzer.c b/fuzz/c/std/gif_fuzzer.c index 380bea35..74cc5156 100644 --- a/fuzz/c/std/gif_fuzzer.c +++ b/fuzz/c/std/gif_fuzzer.c @@ -23,7 +23,7 @@ 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: -g++ -DWUFFS_CONFIG__FUZZLIB_MAIN gif_fuzzer.cc +gcc -DWUFFS_CONFIG__FUZZLIB_MAIN gif_fuzzer.c ./a.out ../../../test/data/*.gif rm -f ./a.out @@ -36,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.cc" +#include "../fuzzlib/fuzzlib.c" void fuzz(wuffs_base__io_reader src_reader, uint32_t hash) { void* pixbuf = NULL; diff --git a/fuzz/c/std/zlib_fuzzer.c b/fuzz/c/std/zlib_fuzzer.c index 85538c6a..275c727d 100644 --- a/fuzz/c/std/zlib_fuzzer.c +++ b/fuzz/c/std/zlib_fuzzer.c @@ -23,7 +23,7 @@ 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: -g++ -DWUFFS_CONFIG__FUZZLIB_MAIN zlib_fuzzer.cc +gcc -DWUFFS_CONFIG__FUZZLIB_MAIN zlib_fuzzer.c ./a.out ../../../test/data/*.zlib rm -f ./a.out @@ -38,7 +38,7 @@ It should print "PASS", amongst other information, and exit(0). #include "../../../gen/c/std/adler32.c" #include "../../../gen/c/std/deflate.c" #include "../../../gen/c/std/zlib.c" -#include "../fuzzlib/fuzzlib.cc" +#include "../fuzzlib/fuzzlib.c" void fuzz(wuffs_base__io_reader src_reader, uint32_t hash) { wuffs_zlib__status s;