diff --git a/example/crc32/crc32.cc b/example/crc32/crc32.cc index 5d63c99a..9fc6faeb 100644 --- a/example/crc32/crc32.cc +++ b/example/crc32/crc32.cc @@ -58,8 +58,8 @@ for a C++ compiler $CXX, such as clang++ or g++. uint8_t src_buffer[SRC_BUFFER_SIZE]; int main(int argc, char** argv) { - wuffs_crc32__ieee_hasher h = ((wuffs_crc32__ieee_hasher){}); - const char* status = h.check_wuffs_version(sizeof h, WUFFS_VERSION); + wuffs_crc32__ieee_hasher h; + const char* status = h.initialize(sizeof h, WUFFS_VERSION, 0); if (status) { fprintf(stderr, "%s\n", status); return 1; diff --git a/example/gifplayer/gifplayer.c b/example/gifplayer/gifplayer.c index ed2fa022..666d7b53 100644 --- a/example/gifplayer/gifplayer.c +++ b/example/gifplayer/gifplayer.c @@ -288,9 +288,9 @@ const char* allocate(wuffs_gif__decoder* dec, wuffs_base__image_config* ic) { } const char* play() { - wuffs_gif__decoder dec = ((wuffs_gif__decoder){}); + wuffs_gif__decoder dec; wuffs_base__status status = - wuffs_gif__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION); + wuffs_gif__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0); if (status) { return status; } diff --git a/example/library/library.c b/example/library/library.c index 7a61eea4..5c20f258 100644 --- a/example/library/library.c +++ b/example/library/library.c @@ -86,8 +86,9 @@ static const char* decode() { if (!dec) { return "out of memory"; } - const char* status = wuffs_deflate__decoder__check_wuffs_version( - dec, sizeof__wuffs_deflate__decoder(), WUFFS_VERSION); + const char* status = wuffs_deflate__decoder__initialize( + dec, sizeof__wuffs_deflate__decoder(), WUFFS_VERSION, + WUFFS_INITIALIZE__ALREADY_ZEROED); if (status) { free(dec); return status; diff --git a/example/zcat/zcat.c b/example/zcat/zcat.c index 1443157a..ca5d6e49 100644 --- a/example/zcat/zcat.c +++ b/example/zcat/zcat.c @@ -79,9 +79,9 @@ uint8_t work_buffer[WORK_BUFFER_SIZE]; static void ignore_return_value(int ignored) {} static const char* decode() { - wuffs_gzip__decoder dec = ((wuffs_gzip__decoder){}); + wuffs_gzip__decoder dec; const char* status = - wuffs_gzip__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION); + wuffs_gzip__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0); if (status) { return status; } diff --git a/fuzz/c/std/gif_fuzzer.c b/fuzz/c/std/gif_fuzzer.c index 4220344e..68ccf7ca 100644 --- a/fuzz/c/std/gif_fuzzer.c +++ b/fuzz/c/std/gif_fuzzer.c @@ -56,9 +56,11 @@ const char* fuzz(wuffs_base__io_reader src_reader, uint32_t hash) { // Use a {} code block so that "goto exit" doesn't trigger "jump bypasses // variable initialization" warnings. { - wuffs_gif__decoder dec = ((wuffs_gif__decoder){}); - const char* status = wuffs_gif__decoder__check_wuffs_version( - &dec, sizeof dec, WUFFS_VERSION); + wuffs_gif__decoder dec; + const char* status = wuffs_gif__decoder__initialize( + &dec, sizeof dec, WUFFS_VERSION, + (hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED + : 0); if (status) { ret = status; goto exit; diff --git a/fuzz/c/std/zlib_fuzzer.c b/fuzz/c/std/zlib_fuzzer.c index 063e376d..ffded01f 100644 --- a/fuzz/c/std/zlib_fuzzer.c +++ b/fuzz/c/std/zlib_fuzzer.c @@ -61,9 +61,10 @@ uint8_t work_buffer[1]; #endif const char* fuzz(wuffs_base__io_reader src_reader, uint32_t hash) { - wuffs_zlib__decoder dec = ((wuffs_zlib__decoder){}); - const char* status = - wuffs_zlib__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION); + wuffs_zlib__decoder dec; + const char* status = wuffs_zlib__decoder__initialize( + &dec, sizeof dec, WUFFS_VERSION, + (hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED : 0); if (status) { return status; } @@ -71,7 +72,7 @@ const char* fuzz(wuffs_base__io_reader src_reader, uint32_t hash) { // Ignore the checksum for 99.99%-ish of all input. When fuzzers generate // random input, the checkum is very unlikely to match. Still, it's useful to // verify that checksumming does not lead to e.g. buffer overflows. - wuffs_zlib__decoder__set_ignore_checksum(&dec, hash & 0xFFFF); + wuffs_zlib__decoder__set_ignore_checksum(&dec, hash & 0xFFFE); uint8_t dst_buffer[DST_BUFFER_SIZE]; wuffs_base__io_buffer dst = ((wuffs_base__io_buffer){ diff --git a/script/bench-c-deflate-fragmentation.c b/script/bench-c-deflate-fragmentation.c index 94b400e2..c49aa9a6 100644 --- a/script/bench-c-deflate-fragmentation.c +++ b/script/bench-c-deflate-fragmentation.c @@ -112,6 +112,14 @@ uint8_t idat_buffer[SRC_BUFFER_SIZE] = {0}; size_t idat_splits[MAX_IDAT_CHUNKS + 1] = {0}; uint32_t num_idat_chunks = 0; +#define WORK_BUFFER_SIZE WUFFS_ZLIB__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE +#if WORK_BUFFER_SIZE > 0 +uint8_t work_buffer[WORK_BUFFER_SIZE]; +#else +// Not all C/C++ compilers support 0-length arrays. +uint8_t work_buffer[1]; +#endif + uint32_t width = 0; uint32_t height = 0; uint64_t bytes_per_pixel = 0; @@ -218,9 +226,9 @@ const char* process_png_chunks(uint8_t* p, size_t n) { } const char* decode_once(bool frag_dst, bool frag_idat) { - wuffs_zlib__decoder dec = ((wuffs_zlib__decoder){}); + wuffs_zlib__decoder dec; const char* status = - wuffs_zlib__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION); + wuffs_zlib__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0); if (status) { return status; } @@ -259,7 +267,11 @@ const char* decode_once(bool frag_dst, bool frag_idat) { while (true) { status = - wuffs_zlib__decoder__decode_io_writer(&dec, dst_writer, idat_reader); + wuffs_zlib__decoder__decode_io_writer(&dec, dst_writer, idat_reader, + ((wuffs_base__slice_u8){ + .ptr = work_buffer, + .len = WORK_BUFFER_SIZE, + })); if (!status) { break;