diff --git a/fuzzing/0000.write/c_file_unlocked.cc b/fuzzing/0000.write/c_file_unlocked.cc index a83b1e019..070982471 100644 --- a/fuzzing/0000.write/c_file_unlocked.cc +++ b/fuzzing/0000.write/c_file_unlocked.cc @@ -1,9 +1,17 @@ #include -fast_io::c_file_unlocked obf("/dev/null", fast_io::open_mode::out); +fast_io::c_file_unlocked obf( +#if defined(_WIN32) && !defined(__WINE__) + "nul" +#else + "/dev/null" +#endif + , + fast_io::open_mode::out); -extern "C" int LLVMFuzzerTestOneInput(std::uint8_t const *ptr, std::size_t n) noexcept +extern "C" int LLVMFuzzerTestOneInput(std::uint8_t const *pptr, std::size_t n) noexcept { - write(obf, ptr, ptr + n); + ::std::byte const *ptr{reinterpret_cast<::std::byte const *>(pptr)}; + ::fast_io::operations::write_all_bytes(obf, ptr, ptr + n); return 0; -} \ No newline at end of file +} diff --git a/fuzzing/0000.write/filebuf_file.cc b/fuzzing/0000.write/filebuf_file.cc new file mode 100644 index 000000000..68cbcf7a5 --- /dev/null +++ b/fuzzing/0000.write/filebuf_file.cc @@ -0,0 +1,21 @@ +#include +#include + +fast_io::filebuf_file obf( +#if defined(_WIN32) && !defined(__WINE__) + "nul" +#else + "/dev/null" +#endif + , + fast_io::open_mode::out); + + +extern "C" int LLVMFuzzerTestOneInput(std::uint8_t const *pptr, std::size_t n) noexcept +{ + char const *ptr{reinterpret_cast(pptr)}; + using namespace fast_io::mnp; + ::fast_io::operations::write_all(obf, ptr, ptr + n); + + return 0; +} diff --git a/fuzzing/0000.write/u32c_file_unlocked.cc b/fuzzing/0000.write/u32c_file_unlocked.cc new file mode 100644 index 000000000..c26c81136 --- /dev/null +++ b/fuzzing/0000.write/u32c_file_unlocked.cc @@ -0,0 +1,24 @@ +#include + +fast_io::u32c_file_unlocked obf( +#if defined(_WIN32) && !defined(__WINE__) + "nul" +#else + "/dev/null" +#endif + , + fast_io::open_mode::out); + +extern "C" + [[__gnu__::__weak__]] + uintptr_t __sancov_lowest_stack{}; + +extern "C" int LLVMFuzzerTestOneInput(std::uint8_t const *pptr, std::size_t n) noexcept +{ + using chartype = char32_t; + char32_t const *ptr{reinterpret_cast(pptr)}; + using namespace fast_io::mnp; + ::fast_io::operations::write_all(obf, ptr, ptr + n / sizeof(char32_t)); + + return 0; +} diff --git a/fuzzing/0000.write/wc_file_unlocked.cc b/fuzzing/0000.write/wc_file_unlocked.cc new file mode 100644 index 000000000..e1bf3c476 --- /dev/null +++ b/fuzzing/0000.write/wc_file_unlocked.cc @@ -0,0 +1,34 @@ +#include + +fast_io::wc_file_unlocked obf( +#if defined(_WIN32) && !defined(__WINE__) + "nul" +#else + "/dev/null" +#endif + , + fast_io::open_mode::out); + +extern "C" + [[__gnu__::__weak__]] + uintptr_t __sancov_lowest_stack{}; + +struct usefwide +{ + usefwide() + { + fwide(obf.fp, 1); + } +}; +#ifdef USE_FWIDE +usefwide t; +#endif + +extern "C" int LLVMFuzzerTestOneInput(std::uint8_t const *pptr, std::size_t n) noexcept +{ + wchar_t const *ptr{reinterpret_cast(pptr)}; + using namespace fast_io::mnp; + ::fast_io::operations::write_all(obf, ptr, ptr + n / sizeof(wchar_t)); + + return 0; +} diff --git a/fuzzing/0000.write/wfilebuf_file.cc b/fuzzing/0000.write/wfilebuf_file.cc new file mode 100644 index 000000000..9192be423 --- /dev/null +++ b/fuzzing/0000.write/wfilebuf_file.cc @@ -0,0 +1,21 @@ +#include +#include + +fast_io::wfilebuf_file obf( +#if defined(_WIN32) && !defined(__WINE__) + "nul" +#else + "/dev/null" +#endif + , + fast_io::open_mode::out); + + +extern "C" int LLVMFuzzerTestOneInput(std::uint8_t const *pptr, std::size_t n) noexcept +{ + wchar_t const *ptr{reinterpret_cast(pptr)}; + using namespace fast_io::mnp; + ::fast_io::operations::write_all(obf, ptr, ptr + n / sizeof(wchar_t)); + + return 0; +} diff --git a/include/fast_io_legacy_impl/c/wincrt.h b/include/fast_io_legacy_impl/c/wincrt.h index 11cf07b31..066e64740 100644 --- a/include/fast_io_legacy_impl/c/wincrt.h +++ b/include/fast_io_legacy_impl/c/wincrt.h @@ -372,16 +372,15 @@ inline T *wincrt_get_buffer_ptr_impl(FILE *__restrict fpp) noexcept } } -template inline void wincrt_set_buffer_curr_ptr_impl(FILE *__restrict fpp, #if __has_cpp_attribute(__gnu__::__may_alias__) [[__gnu__::__may_alias__]] #endif - T *ptr) noexcept + void *ptr) noexcept { crt_iobuf *fp{reinterpret_cast(fpp)}; fp->_cnt -= static_cast<::std::int_least32_t>( - static_cast<::std::uint_least32_t>(static_cast<::std::size_t>(reinterpret_cast(ptr) - fp->_ptr) / sizeof(T))); + static_cast<::std::uint_least32_t>(static_cast<::std::size_t>(reinterpret_cast(ptr) - fp->_ptr))); fp->_ptr = reinterpret_cast(ptr); } #if defined(_MSC_VER) || defined(_UCRT)