~bkerensa/ubuntu/raring/valgrind/merge-from-deb

« back to all changes in this revision

Viewing changes to memcheck/tests/malloc_free_fill.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrés Roldán
  • Date: 2008-06-13 02:31:40 UTC
  • mto: (1.4.1 upstream) (2.2.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: james.westby@ubuntu.com-20080613023140-iwk33rz9rhvfkr96
Import upstream version 3.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* Test for correct functioning of the --malloc-fill and --free-fill
 
3
   flags.  Needs --malloc-fill=0x55 and --free-fill=0x77. */
 
4
 
 
5
#include <stdio.h>
 
6
#include <assert.h>
 
7
#include <stdlib.h>
 
8
 
 
9
int main ( void )
 
10
{
 
11
  int *r, *oldr, *a;
 
12
 
 
13
 
 
14
  fprintf(stderr, "test simple malloc/free:\n");
 
15
 
 
16
  a = malloc(10 * sizeof(int)); assert(a);
 
17
  fprintf(stderr, "(should be malloc-filled)     a[4] = %x\n", a[4]);
 
18
 
 
19
  free(a);
 
20
  fprintf(stderr, "(should be free-filled)       a[5] = %x\n", a[5]);
 
21
 
 
22
 
 
23
 
 
24
  fprintf(stderr, "test realloc-larger:\n");
 
25
 
 
26
  r = malloc(30 * sizeof(int)); assert(r);
 
27
  fprintf(stderr, "(should be malloc-filled)    r[25] = %x\n", r[25]);
 
28
 
 
29
  /* Make larger */
 
30
  oldr = r;
 
31
  r = realloc(r, 40 * sizeof(int)); assert(r);
 
32
 
 
33
  fprintf(stderr, "(should be free-filled)   oldr[26] = %x\n", oldr[26]);
 
34
  fprintf(stderr, "(should be malloc-filled)    r[35] = %x\n", r[35]);
 
35
 
 
36
  free(r);
 
37
 
 
38
 
 
39
 
 
40
  fprintf(stderr, "test realloc-smaller:\n");
 
41
 
 
42
  r = malloc(30 * sizeof(int)); assert(r);
 
43
  fprintf(stderr, "(should be malloc-filled)    r[25] = %x\n", r[25]);
 
44
 
 
45
  /* Make smaller */
 
46
  oldr = r;
 
47
  r = realloc(r, 20 * sizeof(int)); assert(r);
 
48
 
 
49
  fprintf(stderr, "(should be free-filled)   oldr[26] = %x\n", oldr[26]);
 
50
 
 
51
  free(r);
 
52
 
 
53
 
 
54
 
 
55
  fprintf(stderr, "test calloc:\n");
 
56
  a = calloc(100, sizeof(int)); assert(r);
 
57
 
 
58
  fprintf(stderr, "(should be zero)             a[42] = %x\n", a[42]);
 
59
 
 
60
  free(a);
 
61
 
 
62
 
 
63
  return 0;
 
64
}