File: clireq_nofill.c

package info (click to toggle)
valgrind 1%3A3.24.0-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 176,332 kB
  • sloc: ansic: 795,029; exp: 26,134; xml: 23,472; asm: 14,393; cpp: 9,397; makefile: 7,464; sh: 6,122; perl: 5,446; python: 1,498; javascript: 981; awk: 166; csh: 1
file content (42 lines) | stat: -rw-r--r-- 1,240 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "valgrind.h"
#include "../memcheck.h"

struct super { int x; };
static struct super superblock = { 12345 };

/* run with `valgrind -q --malloc-fill=0xaf --free-fill=0xdb` */
int main(int argc, char **argv)
{
    unsigned char *s;
    VALGRIND_CREATE_MEMPOOL(&superblock, /*rzB=*/0, /*is_zeroed=*/0);
    s = malloc(40);
    assert(s);
    assert(*s == 0xaf);
    *s = 0x05;
    VALGRIND_MEMPOOL_ALLOC(&superblock, s, 40);
    printf("*s=%#hhx after MEMPOOL_ALLOC\n", *s);
    VALGRIND_MEMPOOL_FREE(&superblock, s);
    printf("*s=%#hhx after MEMPOOL_FREE\n", *s);
    VALGRIND_MEMPOOL_ALLOC(&superblock, s, 40);
    printf("*s=%#hhx after second MEMPOOL_ALLOC\n", *s);
    free(s);
    VALGRIND_DESTROY_MEMPOOL(&superblock);

    s = malloc(40);
    assert(s);
    assert(*s == 0xaf);
    *s = 0x05;
    VALGRIND_MALLOCLIKE_BLOCK(s, 40, 0/*rzB*/, 0/*is_zeroed*/);
    printf("*s=%#hhx after MALLOCLIKE_BLOCK\n", *s);
    VALGRIND_FREELIKE_BLOCK(s, 0/*rzB*/);
    printf("*s=%#hhx after FREELIKE_BLOCK\n", *s);
    VALGRIND_MALLOCLIKE_BLOCK(s, 40, 0/*rzB*/, 0/*is_zeroed*/);
    printf("*s=%#hhx after second MALLOCLIKE_BLOCK\n", *s);

    return 0;
}