Add missing zstd.h to coregrind Makefile.am noinst_HEADERS
[valgrind.git] / memcheck / tests / realloc_size_zero_mismatch.cpp
blobba809ee17bcc120c430c364c30b47eb80bdfd107
1 #include <iostream>
2 #include <cstdlib>
3 #include <cstdio>
4 #include <cerrno>
6 using std::realloc;
7 using std::cout;
8 using std::perror;
10 int main(void)
12 char* p = new char[1024];
13 p[0] = '\0';
14 errno = 0;
15 // mismatch
16 p = static_cast<char *>(realloc(p, 0));
17 if (p) {
18 cout << "p not nullptr after realloc 0\n";
19 } else {
20 cout << "p is nullptr after realloc 0\n";
22 if (errno) {
23 perror("realloc(something, 0):");
25 // mismatch again
26 delete [] p;
28 errno = 0;
29 volatile void *ptr = NULL;
30 volatile size_t size = 0U;
31 char *p2 = static_cast<char *>(realloc(const_cast<void*>(ptr), size));
32 if (p2) {
33 cout << "p2 not nullptr after realloc 0\n";
34 } else {
35 cout << "p2 is nullptr after realloc 0\n";
37 if (errno) {
38 perror("realloc(NULL, 0):");
40 // mismatch
41 delete [] p2;