Squashed 'external/toxcore/c-toxcore/' changes from 67badf694..82460b212

82460b212 feat: add ngc events
24b54722a fix: Ensure we have allocators available for the error paths.
48dbcfebc cleanup: Remove redundant `-DSODIUM_EXPORT` from definitions.
0cef46ee9 cleanup: Fix a few more clang-tidy warnings.
0c5b918e9 cleanup: Fix a few more clang-tidy warnings.
4d3c97f49 cleanup: Enforce stricter identifier naming using clang-tidy.
a549807df refactor: Add `mem` module to allow tests to override allocators.
6133fb153 chore: Add devcontainer setup for codespaces.
620e07ecd chore: Set a timeout for tests started using Conan
c0ec33b16 chore: Migrate Windows CI from Appveyor to Azure DevOps
8ed47f3ef fix incorrect documentation
a1e245841 docs: Fix doxygen config and remove some redundant comments.
b0f633185 chore: Fix the Android CI job
7469a529b fix: Add missing `#include <array>`.
2b1a6b0d2 add missing ngc constants getter declarations and definitions
2e02d5637 chore: Add missing module dependencies.
REVERT: 67badf694 feat: add ngc events

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: 82460b2124216af1ac9d63060de310a682a2fd15
This commit is contained in:
2023-10-10 19:37:39 +02:00
parent 227425b90e
commit a3126d581b
114 changed files with 2090 additions and 1653 deletions

View File

@ -62,6 +62,33 @@ static int recv_common(Fuzz_Data &input, uint8_t *buf, size_t buf_len)
return res;
}
template <typename F>
static void *alloc_common(Fuzz_Data &data, F func)
{
CONSUME1_OR_RETURN_VAL(const uint8_t want_alloc, data, func());
if (!want_alloc) {
return nullptr;
}
return func();
}
static constexpr Memory_Funcs fuzz_memory_funcs = {
/* .malloc = */
![](Fuzz_System *self, uint32_t size) {
return alloc_common(self->data, [=]() { return std::malloc(size); });
},
/* .calloc = */
![](Fuzz_System *self, uint32_t nmemb, uint32_t size) {
return alloc_common(self->data, [=]() { return std::calloc(nmemb, size); });
},
/* .realloc = */
![](Fuzz_System *self, void *ptr, uint32_t size) {
return alloc_common(self->data, [=]() { return std::realloc(ptr, size); });
},
/* .free = */
![](Fuzz_System *self, void *ptr) { std::free(ptr); },
};
static constexpr Network_Funcs fuzz_network_funcs = {
/* .close = */ ![](Fuzz_System *self, int sock) { return 0; },
/* .accept = */ ![](Fuzz_System *self, int sock) { return 1337; },
@ -149,6 +176,7 @@ static constexpr Random_Funcs fuzz_random_funcs = {
Fuzz_System::Fuzz_System(Fuzz_Data &input)
: System{
std::make_unique<Tox_System>(),
std::make_unique<Memory>(Memory{&fuzz_memory_funcs, this}),
std::make_unique<Network>(Network{&fuzz_network_funcs, this}),
std::make_unique<Random>(Random{&fuzz_random_funcs, this}),
}
@ -156,10 +184,22 @@ Fuzz_System::Fuzz_System(Fuzz_Data &input)
{
sys->mono_time_callback = ![](Fuzz_System *self) { return self->clock; };
sys->mono_time_user_data = this;
sys->mem = mem.get();
sys->ns = ns.get();
sys->rng = rng.get();
}
static constexpr Memory_Funcs null_memory_funcs = {
/* .malloc = */
![](Null_System *self, uint32_t size) { return std::malloc(size); },
/* .calloc = */
![](Null_System *self, uint32_t nmemb, uint32_t size) { return std::calloc(nmemb, size); },
/* .realloc = */
![](Null_System *self, void *ptr, uint32_t size) { return std::realloc(ptr, size); },
/* .free = */
![](Null_System *self, void *ptr) { std::free(ptr); },
};
static constexpr Network_Funcs null_network_funcs = {
/* .close = */ ![](Null_System *self, int sock) { return 0; },
/* .accept = */ ![](Null_System *self, int sock) { return 1337; },
@ -224,12 +264,14 @@ static constexpr Random_Funcs null_random_funcs = {
Null_System::Null_System()
: System{
std::make_unique<Tox_System>(),
std::make_unique<Memory>(Memory{&null_memory_funcs, this}),
std::make_unique<Network>(Network{&null_network_funcs, this}),
std::make_unique<Random>(Random{&null_random_funcs, this}),
}
{
sys->mono_time_callback = ![](Fuzz_System *self) { return self->clock; };
sys->mono_time_user_data = this;
sys->mem = mem.get();
sys->ns = ns.get();
sys->rng = rng.get();
}
@ -244,6 +286,8 @@ static uint16_t get_port(const Network_Addr *addr)
}
}
static constexpr Memory_Funcs record_memory_funcs = null_memory_funcs;
static constexpr Network_Funcs record_network_funcs = {
/* .close = */ ![](Record_System *self, int sock) { return 0; },
/* .accept = */ ![](Record_System *self, int sock) { return 2; },
@ -348,6 +392,7 @@ static constexpr Random_Funcs record_random_funcs = {
Record_System::Record_System(Global &global, uint64_t seed, const char *name)
: System{
std::make_unique<Tox_System>(),
std::make_unique<Memory>(Memory{&record_memory_funcs, this}),
std::make_unique<Network>(Network{&record_network_funcs, this}),
std::make_unique<Random>(Random{&record_random_funcs, this}),
}
@ -357,6 +402,7 @@ Record_System::Record_System(Global &global, uint64_t seed, const char *name)
{
sys->mono_time_callback = ![](Fuzz_System *self) { return self->clock; };
sys->mono_time_user_data = this;
sys->mem = mem.get();
sys->ns = ns.get();
sys->rng = rng.get();
}