Project

General

Profile

Bug #4229 ยป test.c

Josef Sipek, 2013-10-18 12:51 AM

 
1
#include <stdio.h>
2
#include <string.h>
3
#include <umem.h>
4

    
5
#define MAXLEN 32
6

    
7
#define SIZE 120
8
#define ALIGN 0
9

    
10
umem_cache_t *cache;
11

    
12
static void mkcache(int len)
13
{
14
	char name[MAXLEN + 1];
15

    
16
	sprintf(name, "%.*s", len,
17
		"12345678901234567890123456789012345678901234567890");
18

    
19
	fprintf(stderr, "making cache of length %d: %s\n", len, name);
20

    
21
	cache = umem_cache_create(name, SIZE, ALIGN, NULL, NULL, NULL, NULL,
22
				  NULL, 0);
23
}
24

    
25
int main(int argc, char **argv)
26
{
27
	int len;
28

    
29
	if (argc != 2) {
30
		fprintf(stderr, "%s <namelen>\n", argv[0]);
31
		return 1;
32
	}
33

    
34
	len = atoi(argv[1]);
35

    
36
	if ((len < 0) || (len > MAXLEN)) {
37
		fprintf(stderr, "len must be in [0, %d]\n",
38
			MAXLEN);
39
		return 1;
40
	}
41

    
42
	mkcache(len);
43

    
44
	/* now segv */
45
	*((int *) NULL) = 0;
46

    
47
	return 0;
48
}
    (1-1/1)