Add missing zstd.h to coregrind Makefile.am noinst_HEADERS
[valgrind.git] / memcheck / tests / duplicate_align_size_errors.cpp
blob3e0af0d160676baec8587c06e8ccae21e99aef69
1 #include <new>
2 #include <cassert>
3 #include <cstdlib>
4 #include "tests/malloc.h"
5 #include "../../config.h"
7 int main()
9 std::align_val_t misalign(static_cast<std::align_val_t>(63U));
10 std::align_val_t zeroalign(static_cast<std::align_val_t>(0U));
11 std::align_val_t onealign(static_cast<std::align_val_t>(1U));
12 std::align_val_t align(static_cast<std::align_val_t>(64U));
13 std::align_val_t alignx2(static_cast<std::align_val_t>(128U));
14 std::size_t size(32);
15 std::nothrow_t tag;
16 void *mem = nullptr;
18 for (int i = 0 ; i < 2 ; ++i)
20 // Err_BadAlign alignment only
21 mem = operator new(size, zeroalign, tag);
22 operator delete(mem, zeroalign, tag);
23 mem = nullptr;
25 #if defined(HAVE_ALIGNED_ALLOC)
26 // Err_BadAlign size and alignment
27 mem = aligned_alloc(64U, 100U);
28 if (mem)
30 free(mem);
31 mem = nullptr;
34 // Err.BadSize
35 mem = aligned_alloc(64U, 0U);
36 if (mem)
38 free(mem);
39 mem = nullptr;
41 #endif
43 // Err_SizeMismatch
44 mem = operator new(size, align);
45 operator delete(mem, size+1, align);
46 mem = nullptr;
48 // Err_AlignMismatch
49 mem = operator new[](size, align);
50 operator delete[](mem, size, alignx2);
51 mem = nullptr;