2 /* A test which involves copying (using realloc) a block containing
3 some partially defined bytes. Really this is to check that
4 copy_address_range_perms in mc_main.c works. I don't think it's a
5 good test - it may well not exercise all the code in
6 copy_address_range_perms. */
11 #include "memcheck/memcheck.h"
13 typedef unsigned char UChar;
14 typedef unsigned int UInt;
18 static inline UInt myrand ( UInt size )
20 /* From "Numerical Recipes in C" 2nd Edition */
21 seed = 1664525UL * seed + 1013904223UL;
25 static void barf ( int size, int offset )
27 printf("pdb-realloc2: fail: size %d, offset %d\n", size,offset);
31 void do_test ( int size )
35 UChar* p = malloc(size);
39 for (i = 0; i < size; i++) {
41 j = myrand( 256 * 25 );
47 if (j >= 256 && j < 256*13) {
58 for (i = 1; i <= 100; i++) {
59 p = realloc(p, size+i);
66 r = VALGRIND_GET_VBITS(p,v, size+100);
69 //for (i = 0; i < size+100; i++)
70 // printf("%02x ", (UInt)v[i]);
74 for (i = 0; i < size; i++) {
76 j = myrand( 256 * 25 );
79 // expecting a defined value
83 // expecting a PDB == j
90 // in the extension area, everything should be undefined
91 for (i = 0; i < 100; i++) {
92 if (v[size+i] != 0xFF)
103 for (z = 0; z < 100; z++) {
104 printf("pdb_realloc: z = %d\n", z);
109 printf("pdb-realloc2: done\n");