ftmemsim-valgrind/memcheck/tests/calloc-overflow.c
Nicholas Nethercote e3f6e42966 Fixed bug 149878 (calloc overflow). This disables some of the calloc silly
arg checking, but that's no great loss.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10578
2009-07-24 06:41:02 +00:00

21 lines
564 B
C

#include <stdlib.h>
#include <stdio.h>
#include "pub_tool_basics.h"
int main(void)
{
// The n*size multiplication overflows in this example. The only sensible
// thing to do is return NULL, but old versions of Valgrind didn't (they
// often ground to a halt trying to allocate an enormous (but not as
// enormous as asked-for!) block. See bug 149878.
int* x;
#if VG_WORDSIZE == 8
size_t szB = 0x1000000010000001ULL;
#else
size_t szB = 0x10000001UL;
#endif
x = calloc(szB, 0x10);
fprintf(stderr, "x = %#lx\n", (long)x);
return 0;
}