summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/malloc/malloc_general/malloc_general.c
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2025-04-14 17:32:06 +0000
committercvs2svn <admin@example.com>2025-04-14 17:32:06 +0000
commiteb8dd9dca1228af0cd132f515509051ecfabf6f6 (patch)
treeedb6da6af7e865d488dc1a29309f1e1ec226e603 /src/regress/lib/libc/malloc/malloc_general/malloc_general.c
parent247f0352e0ed72a4f476db9dc91f4d982bc83eb2 (diff)
downloadopenbsd-tb_20250414.tar.gz
openbsd-tb_20250414.tar.bz2
openbsd-tb_20250414.zip
This commit was manufactured by cvs2git to create tag 'tb_20250414'.tb_20250414
Diffstat (limited to 'src/regress/lib/libc/malloc/malloc_general/malloc_general.c')
-rw-r--r--src/regress/lib/libc/malloc/malloc_general/malloc_general.c123
1 files changed, 0 insertions, 123 deletions
diff --git a/src/regress/lib/libc/malloc/malloc_general/malloc_general.c b/src/regress/lib/libc/malloc/malloc_general/malloc_general.c
deleted file mode 100644
index b243787bcf..0000000000
--- a/src/regress/lib/libc/malloc/malloc_general/malloc_general.c
+++ /dev/null
@@ -1,123 +0,0 @@
1/* $OpenBSD: malloc_general.c,v 1.7 2022/01/09 07:18:50 otto Exp $ */
2/*
3 * Copyright (c) 2017 Otto Moerbeek <otto@drijf.net>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <err.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22
23/* #define VERBOSE */
24
25#define N 1000
26
27size_t
28size(void)
29{
30 int p = arc4random_uniform(17) + 3;
31 return arc4random_uniform(1 << p);
32}
33
34struct { void *p; size_t sz; } a[N];
35
36void
37fill(u_char *p, size_t sz)
38{
39 size_t i;
40
41 for (i = 0; i < sz; i++)
42 p[i] = i % 256;
43}
44
45void
46check(u_char *p, size_t sz)
47{
48 size_t i;
49
50 for (i = 0; i < sz; i++)
51 if (p[i] != i % 256)
52 errx(1, "check");
53}
54
55int
56main(int argc, char *argv[])
57{
58 int count, p, r, i;
59 void * q;
60 size_t sz;
61
62 for (count = 0; count < 800000; count++) {
63 if (count % 10000 == 0) {
64 printf(".");
65 fflush(stdout);
66 }
67 p = arc4random_uniform(2);
68 i = arc4random_uniform(N);
69 switch (p) {
70 case 0:
71 if (a[i].p) {
72#ifdef VERBOSE
73 printf("F %p\n", a[i].p);
74#endif
75 if (a[i].p)
76 check(a[i].p, a[i].sz);
77 free(a[i].p);
78 a[i].p = NULL;
79 }
80 sz = size();
81#ifdef VERBOSE
82 printf("M %zu=", sz);
83#endif
84 r = arc4random_uniform(2);
85 a[i].p = r == 0 ? malloc_conceal(sz) : malloc(sz);
86 a[i].sz = sz;
87#ifdef VERBOSE
88 printf("%p\n", a[i].p);
89#endif
90 if (a[i].p)
91 fill(a[i].p, sz);
92 break;
93 case 1:
94 sz = size();
95#ifdef VERBOSE
96 printf("R %p %zu=", a[i].p, sz);
97#endif
98 q = realloc(a[i].p, sz);
99#ifdef VERBOSE
100 printf("%p\n", q);
101#endif
102 if (a[i].p && q)
103 check(q, a[i].sz < sz ? a[i].sz : sz);
104 if (q) {
105 a[i].p = q;
106 a[i].sz = sz;
107 fill(a[i].p, sz);
108 }
109 break;
110 }
111 }
112 for (i = 0; i < N; i++) {
113 if (a[i].p)
114 check(a[i].p, a[i].sz);
115 r = arc4random_uniform(2);
116 if (r)
117 free(a[i].p);
118 else
119 freezero(a[i].p, a[i].sz);
120 }
121 printf("\n");
122 return 0;
123}