Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/MacroModel/fast_io
Browse files Browse the repository at this point in the history
  • Loading branch information
MacroModel committed Dec 6, 2024
2 parents aed9d04 + 6a4d188 commit 24de435
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 7 deletions.
16 changes: 12 additions & 4 deletions fuzzing/0000.write/c_file_unlocked.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
#include <fast_io.h>

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;
}
}
21 changes: 21 additions & 0 deletions fuzzing/0000.write/filebuf_file.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <fast_io.h>
#include <fast_io_legacy.h>

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<char const *>(pptr)};
using namespace fast_io::mnp;
::fast_io::operations::write_all(obf, ptr, ptr + n);

return 0;
}
24 changes: 24 additions & 0 deletions fuzzing/0000.write/u32c_file_unlocked.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <fast_io.h>

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<char32_t const *>(pptr)};
using namespace fast_io::mnp;
::fast_io::operations::write_all(obf, ptr, ptr + n / sizeof(char32_t));

return 0;
}
34 changes: 34 additions & 0 deletions fuzzing/0000.write/wc_file_unlocked.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <fast_io.h>

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<wchar_t const *>(pptr)};
using namespace fast_io::mnp;
::fast_io::operations::write_all(obf, ptr, ptr + n / sizeof(wchar_t));

return 0;
}
21 changes: 21 additions & 0 deletions fuzzing/0000.write/wfilebuf_file.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <fast_io.h>
#include <fast_io_legacy.h>

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<wchar_t const *>(pptr)};
using namespace fast_io::mnp;
::fast_io::operations::write_all(obf, ptr, ptr + n / sizeof(wchar_t));

return 0;
}
5 changes: 2 additions & 3 deletions include/fast_io_legacy_impl/c/wincrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,15 @@ inline T *wincrt_get_buffer_ptr_impl(FILE *__restrict fpp) noexcept
}
}

template <typename T>
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<crt_iobuf *>(fpp)};
fp->_cnt -= static_cast<::std::int_least32_t>(
static_cast<::std::uint_least32_t>(static_cast<::std::size_t>(reinterpret_cast<char *>(ptr) - fp->_ptr) / sizeof(T)));
static_cast<::std::uint_least32_t>(static_cast<::std::size_t>(reinterpret_cast<char *>(ptr) - fp->_ptr)));
fp->_ptr = reinterpret_cast<char *>(ptr);
}
#if defined(_MSC_VER) || defined(_UCRT)
Expand Down

0 comments on commit 24de435

Please sign in to comment.