Simplified logic of parsing sizes of rice-partitions
[flac.git] / oss-fuzz / fuzzing / memory.hpp
blob804e23b48a5f29d4ef23916e9ba3903abacbad0c
1 #pragma once
3 #include <stdio.h>
4 #include <optional>
6 #ifndef ASAN
7 #define ASAN 0
8 #endif
10 #ifndef MSAN
11 #define MSAN 0
12 #endif
14 namespace fuzzing {
15 namespace memory {
17 #ifndef FUZZING_HEADERS_NO_IMPL
18 #if ASAN == 1
19 extern "C" void *__asan_region_is_poisoned(const void *beg, size_t size);
20 #endif
22 #if MSAN == 1
23 extern "C" void __msan_check_mem_is_initialized(const volatile void *x, size_t size);
24 #endif
26 void memory_test_asan(const void* data, const size_t size)
28 (void)data;
29 (void)size;
31 #if ASAN == 1
32 if ( __asan_region_is_poisoned(data, size) != NULL ) {
33 abort();
35 #endif
38 void memory_test_msan(const void* data, const size_t size)
40 (void)data;
41 (void)size;
43 #if MSAN == 1
44 __msan_check_mem_is_initialized(data, size);
45 #endif
48 void memory_test(const void* data, const size_t size)
50 memory_test_asan(data, size);
51 memory_test_msan(data, size);
54 template <class T>
55 void memory_test(const T& t)
57 (void)t;
60 template <>
61 void memory_test(const std::string& s)
63 (void)s;
65 #if MSAN == 1
66 memory_test(s.data(), s.size());
67 #endif
70 #endif
72 } /* namespace memory */
73 } /* namespace fuzzing */