diff --git a/test/large_array_growth.c b/test/large_array_growth.c index dfa61a0..09f89c5 100644 --- a/test/large_array_growth.c +++ b/test/large_array_growth.c @@ -1,8 +1,9 @@ #include #include -__attribute__((optimize(0))) -int main(void) { +#include "test_util.h" + +OPTNONE int main(void) { void *p = NULL; size_t size = 256 * 1024; diff --git a/test/mallinfo.c b/test/mallinfo.c index 2fc5246..dc96670 100644 --- a/test/mallinfo.c +++ b/test/mallinfo.c @@ -1,7 +1,10 @@ +#include + #include -__attribute__((optimize(0))) -int main(void) { +#include "test_util.h" + +OPTNONE int main(void) { malloc(1024 * 1024 * 1024); malloc(16); malloc(32); diff --git a/test/malloc_info.c b/test/malloc_info.c index c1590af..62a315f 100644 --- a/test/malloc_info.c +++ b/test/malloc_info.c @@ -1,16 +1,18 @@ #include +#include #include -__attribute__((optimize(0))) -void leak_memory(void) { +#include "test_util.h" + +OPTNONE static void leak_memory(void) { (void)malloc(1024 * 1024 * 1024); (void)malloc(16); (void)malloc(32); (void)malloc(4096); } -void *do_work(void *p) { +static void *do_work(void *p) { leak_memory(); return NULL; } diff --git a/test/simple-memory-corruption/delete_type_size_mismatch.cc b/test/simple-memory-corruption/delete_type_size_mismatch.cc index a3b13b4..ffbb731 100644 --- a/test/simple-memory-corruption/delete_type_size_mismatch.cc +++ b/test/simple-memory-corruption/delete_type_size_mismatch.cc @@ -1,11 +1,12 @@ #include +#include "../test_util.h" + struct foo { uint64_t a, b, c, d; }; -__attribute__((optimize(0))) -int main(void) { +OPTNONE int main(void) { void *p = new char; struct foo *c = (struct foo *)p; delete c; diff --git a/test/simple-memory-corruption/double_free_large.c b/test/simple-memory-corruption/double_free_large.c index ce4850d..0c7412b 100644 --- a/test/simple-memory-corruption/double_free_large.c +++ b/test/simple-memory-corruption/double_free_large.c @@ -1,7 +1,8 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { void *p = malloc(128 * 1024); if (!p) { return 1; diff --git a/test/simple-memory-corruption/double_free_large_delayed.c b/test/simple-memory-corruption/double_free_large_delayed.c index b448ea9..f367590 100644 --- a/test/simple-memory-corruption/double_free_large_delayed.c +++ b/test/simple-memory-corruption/double_free_large_delayed.c @@ -1,7 +1,8 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { void *p = malloc(128 * 1024); if (!p) { return 1; diff --git a/test/simple-memory-corruption/double_free_small.c b/test/simple-memory-corruption/double_free_small.c index 399b8d0..4635d36 100644 --- a/test/simple-memory-corruption/double_free_small.c +++ b/test/simple-memory-corruption/double_free_small.c @@ -1,7 +1,8 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { void *p = malloc(16); if (!p) { return 1; diff --git a/test/simple-memory-corruption/double_free_small_delayed.c b/test/simple-memory-corruption/double_free_small_delayed.c index 63d8586..acb4034 100644 --- a/test/simple-memory-corruption/double_free_small_delayed.c +++ b/test/simple-memory-corruption/double_free_small_delayed.c @@ -1,7 +1,8 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { void *p = malloc(16); if (!p) { return 1; diff --git a/test/simple-memory-corruption/eight_byte_overflow_large.c b/test/simple-memory-corruption/eight_byte_overflow_large.c index afb25b8..3b8c8d3 100644 --- a/test/simple-memory-corruption/eight_byte_overflow_large.c +++ b/test/simple-memory-corruption/eight_byte_overflow_large.c @@ -1,7 +1,8 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { char *p = malloc(256 * 1024); if (!p) { return 1; diff --git a/test/simple-memory-corruption/eight_byte_overflow_small.c b/test/simple-memory-corruption/eight_byte_overflow_small.c index 6270ac3..0ac796b 100644 --- a/test/simple-memory-corruption/eight_byte_overflow_small.c +++ b/test/simple-memory-corruption/eight_byte_overflow_small.c @@ -1,7 +1,8 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { char *p = malloc(8); if (!p) { return 1; diff --git a/test/simple-memory-corruption/invalid_free_protected.c b/test/simple-memory-corruption/invalid_free_protected.c index 97d5be1..ee81467 100644 --- a/test/simple-memory-corruption/invalid_free_protected.c +++ b/test/simple-memory-corruption/invalid_free_protected.c @@ -2,8 +2,9 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { free(malloc(16)); char *p = mmap(NULL, 4096 * 16, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); if (p == MAP_FAILED) { diff --git a/test/simple-memory-corruption/invalid_free_small_region.c b/test/simple-memory-corruption/invalid_free_small_region.c index d7f9321..4993724 100644 --- a/test/simple-memory-corruption/invalid_free_small_region.c +++ b/test/simple-memory-corruption/invalid_free_small_region.c @@ -1,7 +1,8 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { char *p = malloc(16); if (!p) { return 1; diff --git a/test/simple-memory-corruption/invalid_free_small_region_far.c b/test/simple-memory-corruption/invalid_free_small_region_far.c index 4a7ed29..c147ef3 100644 --- a/test/simple-memory-corruption/invalid_free_small_region_far.c +++ b/test/simple-memory-corruption/invalid_free_small_region_far.c @@ -1,7 +1,8 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { char *p = malloc(16); if (!p) { return 1; diff --git a/test/simple-memory-corruption/invalid_free_unprotected.c b/test/simple-memory-corruption/invalid_free_unprotected.c index 01fc630..c583c6b 100644 --- a/test/simple-memory-corruption/invalid_free_unprotected.c +++ b/test/simple-memory-corruption/invalid_free_unprotected.c @@ -2,8 +2,9 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { free(malloc(16)); char *p = mmap(NULL, 4096 * 16, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); if (p == MAP_FAILED) { diff --git a/test/simple-memory-corruption/invalid_malloc_usable_size_small.c b/test/simple-memory-corruption/invalid_malloc_usable_size_small.c index 3a155b2..f200564 100644 --- a/test/simple-memory-corruption/invalid_malloc_usable_size_small.c +++ b/test/simple-memory-corruption/invalid_malloc_usable_size_small.c @@ -1,7 +1,8 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { char *p = malloc(16); if (!p) { return 1; diff --git a/test/simple-memory-corruption/invalid_malloc_usable_size_small_quarantine.c b/test/simple-memory-corruption/invalid_malloc_usable_size_small_quarantine.c index 5a8f3ea..ae0a8c6 100644 --- a/test/simple-memory-corruption/invalid_malloc_usable_size_small_quarantine.c +++ b/test/simple-memory-corruption/invalid_malloc_usable_size_small_quarantine.c @@ -1,7 +1,8 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { void *p = malloc(16); if (!p) { return 1; diff --git a/test/simple-memory-corruption/malloc_object_size.c b/test/simple-memory-corruption/malloc_object_size.c index 630134d..04e6350 100644 --- a/test/simple-memory-corruption/malloc_object_size.c +++ b/test/simple-memory-corruption/malloc_object_size.c @@ -1,10 +1,11 @@ #include #include +#include "../test_util.h" + size_t malloc_object_size(void *ptr); -__attribute__((optimize(0))) -int main(void) { +OPTNONE int main(void) { char *p = malloc(16); size_t size = malloc_object_size(p); return size != (SLAB_CANARY ? 24 : 32); diff --git a/test/simple-memory-corruption/malloc_object_size_offset.c b/test/simple-memory-corruption/malloc_object_size_offset.c index 3d389a0..2bc16b6 100644 --- a/test/simple-memory-corruption/malloc_object_size_offset.c +++ b/test/simple-memory-corruption/malloc_object_size_offset.c @@ -1,10 +1,11 @@ #include #include +#include "../test_util.h" + size_t malloc_object_size(void *ptr); -__attribute__((optimize(0))) -int main(void) { +OPTNONE int main(void) { char *p = malloc(16); size_t size = malloc_object_size(p + 5); return size != (SLAB_CANARY ? 19 : 27); diff --git a/test/simple-memory-corruption/read_after_free_large.c b/test/simple-memory-corruption/read_after_free_large.c index 81e8628..b5e611c 100644 --- a/test/simple-memory-corruption/read_after_free_large.c +++ b/test/simple-memory-corruption/read_after_free_large.c @@ -2,8 +2,9 @@ #include #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { char *p = malloc(128 * 1024); if (!p) { return 1; diff --git a/test/simple-memory-corruption/read_after_free_small.c b/test/simple-memory-corruption/read_after_free_small.c index cc4d154..7d53e5c 100644 --- a/test/simple-memory-corruption/read_after_free_small.c +++ b/test/simple-memory-corruption/read_after_free_small.c @@ -2,8 +2,9 @@ #include #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { char *p = malloc(16); if (!p) { return 1; diff --git a/test/simple-memory-corruption/read_zero_size.c b/test/simple-memory-corruption/read_zero_size.c index 7e6ed78..385f4d6 100644 --- a/test/simple-memory-corruption/read_zero_size.c +++ b/test/simple-memory-corruption/read_zero_size.c @@ -1,8 +1,9 @@ #include #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { char *p = malloc(0); if (!p) { return 1; diff --git a/test/simple-memory-corruption/string_overflow.c b/test/simple-memory-corruption/string_overflow.c index fe89fa5..7f54a63 100644 --- a/test/simple-memory-corruption/string_overflow.c +++ b/test/simple-memory-corruption/string_overflow.c @@ -4,8 +4,9 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { char *p = malloc(16); if (!p) { return 1; diff --git a/test/simple-memory-corruption/unaligned_free_large.c b/test/simple-memory-corruption/unaligned_free_large.c index 3bee868..10c7874 100644 --- a/test/simple-memory-corruption/unaligned_free_large.c +++ b/test/simple-memory-corruption/unaligned_free_large.c @@ -1,7 +1,8 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { char *p = malloc(128 * 1024); if (!p) { return 1; diff --git a/test/simple-memory-corruption/unaligned_free_small.c b/test/simple-memory-corruption/unaligned_free_small.c index bf80307..1b2a7fc 100644 --- a/test/simple-memory-corruption/unaligned_free_small.c +++ b/test/simple-memory-corruption/unaligned_free_small.c @@ -1,7 +1,8 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { char *p = malloc(16); if (!p) { return 1; diff --git a/test/simple-memory-corruption/unaligned_malloc_usable_size_small.c b/test/simple-memory-corruption/unaligned_malloc_usable_size_small.c index 89397af..2bbbf8a 100644 --- a/test/simple-memory-corruption/unaligned_malloc_usable_size_small.c +++ b/test/simple-memory-corruption/unaligned_malloc_usable_size_small.c @@ -1,7 +1,8 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { char *p = malloc(16); if (!p) { return 1; diff --git a/test/simple-memory-corruption/uninitialized_free.c b/test/simple-memory-corruption/uninitialized_free.c index 0028be9..9e3c8b9 100644 --- a/test/simple-memory-corruption/uninitialized_free.c +++ b/test/simple-memory-corruption/uninitialized_free.c @@ -1,7 +1,8 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { free((void *)1); return 0; } diff --git a/test/simple-memory-corruption/uninitialized_malloc_usable_size.c b/test/simple-memory-corruption/uninitialized_malloc_usable_size.c index 3b2924f..d0644c4 100644 --- a/test/simple-memory-corruption/uninitialized_malloc_usable_size.c +++ b/test/simple-memory-corruption/uninitialized_malloc_usable_size.c @@ -1,7 +1,8 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { malloc_usable_size((void *)1); return 0; } diff --git a/test/simple-memory-corruption/uninitialized_realloc.c b/test/simple-memory-corruption/uninitialized_realloc.c index e0dc09a..4afc9de 100644 --- a/test/simple-memory-corruption/uninitialized_realloc.c +++ b/test/simple-memory-corruption/uninitialized_realloc.c @@ -1,7 +1,8 @@ #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { void *p = realloc((void *)1, 16); if (!p) { return 1; diff --git a/test/simple-memory-corruption/write_after_free_large.c b/test/simple-memory-corruption/write_after_free_large.c index ce4c691..d46cc0d 100644 --- a/test/simple-memory-corruption/write_after_free_large.c +++ b/test/simple-memory-corruption/write_after_free_large.c @@ -1,8 +1,9 @@ #include #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { char *p = malloc(128 * 1024); if (!p) { return 1; diff --git a/test/simple-memory-corruption/write_after_free_large_reuse.c b/test/simple-memory-corruption/write_after_free_large_reuse.c index c32e77b..3af225e 100644 --- a/test/simple-memory-corruption/write_after_free_large_reuse.c +++ b/test/simple-memory-corruption/write_after_free_large_reuse.c @@ -1,8 +1,9 @@ #include #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { char *p = malloc(128 * 1024); if (!p) { return 1; diff --git a/test/simple-memory-corruption/write_after_free_small.c b/test/simple-memory-corruption/write_after_free_small.c index 2a80835..c78325e 100644 --- a/test/simple-memory-corruption/write_after_free_small.c +++ b/test/simple-memory-corruption/write_after_free_small.c @@ -1,8 +1,9 @@ #include #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { char *p = malloc(128); if (!p) { return 1; diff --git a/test/simple-memory-corruption/write_after_free_small_reuse.c b/test/simple-memory-corruption/write_after_free_small_reuse.c index ca6564e..315407a 100644 --- a/test/simple-memory-corruption/write_after_free_small_reuse.c +++ b/test/simple-memory-corruption/write_after_free_small_reuse.c @@ -1,8 +1,9 @@ #include #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { char *p = malloc(128); if (!p) { return 1; diff --git a/test/simple-memory-corruption/write_zero_size.c b/test/simple-memory-corruption/write_zero_size.c index def29b5..3687bf9 100644 --- a/test/simple-memory-corruption/write_zero_size.c +++ b/test/simple-memory-corruption/write_zero_size.c @@ -1,8 +1,9 @@ #include #include -__attribute__((optimize(0))) -int main(void) { +#include "../test_util.h" + +OPTNONE int main(void) { char *p = malloc(0); if (!p) { return 1; diff --git a/test/test_util.h b/test/test_util.h new file mode 100644 index 0000000..d2d78a6 --- /dev/null +++ b/test/test_util.h @@ -0,0 +1,10 @@ +#ifndef TEST_UTIL_H +#define TEST_UTIL_H + +#ifdef __clang__ +#define OPTNONE __attribute__((optnone)) +#else +#define OPTNONE __attribute__((optimize(0))) +#endif + +#endif