Skip to content

Commit 8f61fde

Browse files
committed
Uniformly cast mallctl[bymib]() oldp/newp arguments to (void *).
This avoids warnings in some cases, and is otherwise generally good hygiene.
1 parent 84ae603 commit 8f61fde

27 files changed

+397
-362
lines changed

doc/jemalloc.xml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ for (i = 0; i < nbins; i++) {
406406
407407
mib[2] = i;
408408
len = sizeof(bin_size);
409-
mallctlbymib(mib, miblen, &bin_size, &len, NULL, 0);
409+
mallctlbymib(mib, miblen, (void *)&bin_size, &len, NULL, 0);
410410
/* Do something with bin_size... */
411411
}]]></programlisting></para>
412412

msvc/projects/vc2015/test_threads/test_threads.cpp

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ int test_threads()
2121
je_malloc_conf = "narenas:3";
2222
int narenas = 0;
2323
size_t sz = sizeof(narenas);
24-
je_mallctl("opt.narenas", &narenas, &sz, NULL, 0);
24+
je_mallctl("opt.narenas", (void *)&narenas, &sz, NULL, 0);
2525
if (narenas != 3) {
2626
printf("Error: unexpected number of arenas: %d\n", narenas);
2727
return 1;
@@ -33,7 +33,7 @@ int test_threads()
3333
je_malloc_stats_print(NULL, NULL, NULL);
3434
size_t allocated1;
3535
size_t sz1 = sizeof(allocated1);
36-
je_mallctl("stats.active", &allocated1, &sz1, NULL, 0);
36+
je_mallctl("stats.active", (void *)&allocated1, &sz1, NULL, 0);
3737
printf("\nPress Enter to start threads...\n");
3838
getchar();
3939
printf("Starting %d threads x %d x %d iterations...\n", numThreads, numIter1, numIter2);
@@ -78,7 +78,7 @@ int test_threads()
7878
}
7979
je_malloc_stats_print(NULL, NULL, NULL);
8080
size_t allocated2;
81-
je_mallctl("stats.active", &allocated2, &sz1, NULL, 0);
81+
je_mallctl("stats.active", (void *)&allocated2, &sz1, NULL, 0);
8282
size_t leaked = allocated2 - allocated1;
8383
printf("\nDone. Leaked: %zd bytes\n", leaked);
8484
bool failed = leaked > 65536; // in case C++ runtime allocated something (e.g. iostream locale or facet)

src/stats.c

100644100755
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#define CTL_GET(n, v, t) do { \
55
size_t sz = sizeof(t); \
6-
xmallctl(n, v, &sz, NULL, 0); \
6+
xmallctl(n, (void *)v, &sz, NULL, 0); \
77
} while (0)
88

99
#define CTL_M2_GET(n, i, v, t) do { \
@@ -12,7 +12,7 @@
1212
size_t sz = sizeof(t); \
1313
xmallctlnametomib(n, mib, &miblen); \
1414
mib[2] = (i); \
15-
xmallctlbymib(mib, miblen, v, &sz, NULL, 0); \
15+
xmallctlbymib(mib, miblen, (void *)v, &sz, NULL, 0); \
1616
} while (0)
1717

1818
#define CTL_M2_M4_GET(n, i, j, v, t) do { \
@@ -22,7 +22,7 @@
2222
xmallctlnametomib(n, mib, &miblen); \
2323
mib[2] = (i); \
2424
mib[4] = (j); \
25-
xmallctlbymib(mib, miblen, v, &sz, NULL, 0); \
25+
xmallctlbymib(mib, miblen, (void *)v, &sz, NULL, 0); \
2626
} while (0)
2727

2828
/******************************************************************************/
@@ -647,7 +647,7 @@ stats_general_print(void (*write_cb)(void *, const char *), void *cbopaque,
647647
#define OPT_WRITE_BOOL_MUTABLE(n, m, c) { \
648648
bool bv2; \
649649
if (je_mallctl("opt."#n, (void *)&bv, &bsz, NULL, 0) == 0 && \
650-
je_mallctl(#m, &bv2, &bsz, NULL, 0) == 0) { \
650+
je_mallctl(#m, &bv2, (void *)&bsz, NULL, 0) == 0) { \
651651
if (json) { \
652652
malloc_cprintf(write_cb, cbopaque, \
653653
"\t\t\t\""#n"\": %s%s\n", bv ? "true" : \
@@ -692,7 +692,7 @@ stats_general_print(void (*write_cb)(void *, const char *), void *cbopaque,
692692
#define OPT_WRITE_SSIZE_T_MUTABLE(n, m, c) { \
693693
ssize_t ssv2; \
694694
if (je_mallctl("opt."#n, (void *)&ssv, &sssz, NULL, 0) == 0 && \
695-
je_mallctl(#m, &ssv2, &sssz, NULL, 0) == 0) { \
695+
je_mallctl(#m, (void *)&ssv2, &sssz, NULL, 0) == 0) { \
696696
if (json) { \
697697
malloc_cprintf(write_cb, cbopaque, \
698698
"\t\t\t\""#n"\": %zd%s\n", ssv, (c)); \
@@ -1084,7 +1084,8 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
10841084
* */
10851085
epoch = 1;
10861086
u64sz = sizeof(uint64_t);
1087-
err = je_mallctl("epoch", &epoch, &u64sz, &epoch, sizeof(uint64_t));
1087+
err = je_mallctl("epoch", (void *)&epoch, &u64sz, (void *)&epoch,
1088+
sizeof(uint64_t));
10881089
if (err != 0) {
10891090
if (err == EAGAIN) {
10901091
malloc_write("<jemalloc>: Memory allocation failure in "

src/tcache.c

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,12 @@ tcache_boot(tsdn_t *tsdn)
517517
* If necessary, clamp opt_lg_tcache_max, now that large_maxclass is
518518
* known.
519519
*/
520-
if (opt_lg_tcache_max < 0 || (1U << opt_lg_tcache_max) < SMALL_MAXCLASS)
520+
if (opt_lg_tcache_max < 0 || (ZU(1) << opt_lg_tcache_max) < SMALL_MAXCLASS)
521521
tcache_maxclass = SMALL_MAXCLASS;
522522
else if ((1U << opt_lg_tcache_max) > large_maxclass)
523523
tcache_maxclass = large_maxclass;
524524
else
525-
tcache_maxclass = (1U << opt_lg_tcache_max);
525+
tcache_maxclass = (ZU(1) << opt_lg_tcache_max);
526526

527527
nhbins = size2index(tcache_maxclass) + 1;
528528

src/util.c

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ malloc_strtoumax(const char *restrict nptr, char **restrict endptr, int base)
200200
p++;
201201
}
202202
if (neg)
203-
ret = -ret;
203+
ret = (uintmax_t)(-((intmax_t)ret));
204204

205205
if (p == ns) {
206206
/* No conversion performed. */

test/integration/MALLOCX_ARENA.c

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ thd_start(void *arg)
1919
size_t sz;
2020

2121
sz = sizeof(arena_ind);
22-
assert_d_eq(mallctl("arenas.extend", &arena_ind, &sz, NULL, 0), 0,
23-
"Error in arenas.extend");
22+
assert_d_eq(mallctl("arenas.extend", (void *)&arena_ind, &sz, NULL, 0),
23+
0, "Error in arenas.extend");
2424

2525
if (thread_ind % 4 != 3) {
2626
size_t mib[3];

test/integration/allocated.c

100644100755
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ thd_start(void *arg)
1818
size_t sz, usize;
1919

2020
sz = sizeof(a0);
21-
if ((err = mallctl("thread.allocated", &a0, &sz, NULL, 0))) {
21+
if ((err = mallctl("thread.allocated", (void *)&a0, &sz, NULL, 0))) {
2222
if (err == ENOENT)
2323
goto label_ENOENT;
2424
test_fail("%s(): Error in mallctl(): %s", __func__,
2525
strerror(err));
2626
}
2727
sz = sizeof(ap0);
28-
if ((err = mallctl("thread.allocatedp", &ap0, &sz, NULL, 0))) {
28+
if ((err = mallctl("thread.allocatedp", (void *)&ap0, &sz, NULL, 0))) {
2929
if (err == ENOENT)
3030
goto label_ENOENT;
3131
test_fail("%s(): Error in mallctl(): %s", __func__,
@@ -36,14 +36,15 @@ thd_start(void *arg)
3636
"storage");
3737

3838
sz = sizeof(d0);
39-
if ((err = mallctl("thread.deallocated", &d0, &sz, NULL, 0))) {
39+
if ((err = mallctl("thread.deallocated", (void *)&d0, &sz, NULL, 0))) {
4040
if (err == ENOENT)
4141
goto label_ENOENT;
4242
test_fail("%s(): Error in mallctl(): %s", __func__,
4343
strerror(err));
4444
}
4545
sz = sizeof(dp0);
46-
if ((err = mallctl("thread.deallocatedp", &dp0, &sz, NULL, 0))) {
46+
if ((err = mallctl("thread.deallocatedp", (void *)&dp0, &sz, NULL,
47+
0))) {
4748
if (err == ENOENT)
4849
goto label_ENOENT;
4950
test_fail("%s(): Error in mallctl(): %s", __func__,
@@ -57,9 +58,9 @@ thd_start(void *arg)
5758
assert_ptr_not_null(p, "Unexpected malloc() error");
5859

5960
sz = sizeof(a1);
60-
mallctl("thread.allocated", &a1, &sz, NULL, 0);
61+
mallctl("thread.allocated", (void *)&a1, &sz, NULL, 0);
6162
sz = sizeof(ap1);
62-
mallctl("thread.allocatedp", &ap1, &sz, NULL, 0);
63+
mallctl("thread.allocatedp", (void *)&ap1, &sz, NULL, 0);
6364
assert_u64_eq(*ap1, a1,
6465
"Dereferenced \"thread.allocatedp\" value should equal "
6566
"\"thread.allocated\" value");
@@ -74,9 +75,9 @@ thd_start(void *arg)
7475
free(p);
7576

7677
sz = sizeof(d1);
77-
mallctl("thread.deallocated", &d1, &sz, NULL, 0);
78+
mallctl("thread.deallocated", (void *)&d1, &sz, NULL, 0);
7879
sz = sizeof(dp1);
79-
mallctl("thread.deallocatedp", &dp1, &sz, NULL, 0);
80+
mallctl("thread.deallocatedp", (void *)&dp1, &sz, NULL, 0);
8081
assert_u64_eq(*dp1, d1,
8182
"Dereferenced \"thread.deallocatedp\" value should equal "
8283
"\"thread.deallocated\" value");

test/integration/chunk.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ TEST_BEGIN(test_chunk)
137137
bool xallocx_success_a, xallocx_success_b, xallocx_success_c;
138138

139139
sz = sizeof(unsigned);
140-
assert_d_eq(mallctl("arenas.extend", &arena_ind, &sz, NULL, 0), 0,
141-
"Unexpected mallctl() failure");
140+
assert_d_eq(mallctl("arenas.extend", (void *)&arena_ind, &sz, NULL, 0),
141+
0, "Unexpected mallctl() failure");
142142
flags = MALLOCX_ARENA(arena_ind) | MALLOCX_TCACHE_NONE;
143143

144144
/* Install custom chunk hooks. */
@@ -148,8 +148,9 @@ TEST_BEGIN(test_chunk)
148148
hooks_mib[1] = (size_t)arena_ind;
149149
old_size = sizeof(chunk_hooks_t);
150150
new_size = sizeof(chunk_hooks_t);
151-
assert_d_eq(mallctlbymib(hooks_mib, hooks_miblen, &old_hooks, &old_size,
152-
&new_hooks, new_size), 0, "Unexpected chunk_hooks error");
151+
assert_d_eq(mallctlbymib(hooks_mib, hooks_miblen, (void *)&old_hooks,
152+
&old_size, (void *)&new_hooks, new_size), 0,
153+
"Unexpected chunk_hooks error");
153154
orig_hooks = old_hooks;
154155
assert_ptr_ne(old_hooks.alloc, chunk_alloc, "Unexpected alloc error");
155156
assert_ptr_ne(old_hooks.dalloc, chunk_dalloc,
@@ -164,18 +165,18 @@ TEST_BEGIN(test_chunk)
164165

165166
/* Get large size classes. */
166167
sz = sizeof(size_t);
167-
assert_d_eq(mallctl("arenas.lrun.0.size", &large0, &sz, NULL, 0), 0,
168-
"Unexpected arenas.lrun.0.size failure");
169-
assert_d_eq(mallctl("arenas.lrun.1.size", &large1, &sz, NULL, 0), 0,
170-
"Unexpected arenas.lrun.1.size failure");
168+
assert_d_eq(mallctl("arenas.lrun.0.size", (void *)&large0, &sz, NULL,
169+
0), 0, "Unexpected arenas.lrun.0.size failure");
170+
assert_d_eq(mallctl("arenas.lrun.1.size", (void *)&large1, &sz, NULL,
171+
0), 0, "Unexpected arenas.lrun.1.size failure");
171172

172173
/* Get huge size classes. */
173-
assert_d_eq(mallctl("arenas.hchunk.0.size", &huge0, &sz, NULL, 0), 0,
174-
"Unexpected arenas.hchunk.0.size failure");
175-
assert_d_eq(mallctl("arenas.hchunk.1.size", &huge1, &sz, NULL, 0), 0,
176-
"Unexpected arenas.hchunk.1.size failure");
177-
assert_d_eq(mallctl("arenas.hchunk.2.size", &huge2, &sz, NULL, 0), 0,
178-
"Unexpected arenas.hchunk.2.size failure");
174+
assert_d_eq(mallctl("arenas.hchunk.0.size", (void *)&huge0, &sz, NULL,
175+
0), 0, "Unexpected arenas.hchunk.0.size failure");
176+
assert_d_eq(mallctl("arenas.hchunk.1.size", (void *)&huge1, &sz, NULL,
177+
0), 0, "Unexpected arenas.hchunk.1.size failure");
178+
assert_d_eq(mallctl("arenas.hchunk.2.size", (void *)&huge2, &sz, NULL,
179+
0), 0, "Unexpected arenas.hchunk.2.size failure");
179180

180181
/* Test dalloc/decommit/purge cascade. */
181182
purge_miblen = sizeof(purge_mib)/sizeof(size_t);
@@ -265,9 +266,9 @@ TEST_BEGIN(test_chunk)
265266

266267
/* Restore chunk hooks. */
267268
assert_d_eq(mallctlbymib(hooks_mib, hooks_miblen, NULL, NULL,
268-
&old_hooks, new_size), 0, "Unexpected chunk_hooks error");
269-
assert_d_eq(mallctlbymib(hooks_mib, hooks_miblen, &old_hooks, &old_size,
270-
NULL, 0), 0, "Unexpected chunk_hooks error");
269+
(void *)&old_hooks, new_size), 0, "Unexpected chunk_hooks error");
270+
assert_d_eq(mallctlbymib(hooks_mib, hooks_miblen, (void *)&old_hooks,
271+
&old_size, NULL, 0), 0, "Unexpected chunk_hooks error");
271272
assert_ptr_eq(old_hooks.alloc, orig_hooks.alloc,
272273
"Unexpected alloc error");
273274
assert_ptr_eq(old_hooks.dalloc, orig_hooks.dalloc,

test/integration/mallocx.c

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ get_nsizes_impl(const char *cmd)
1111
size_t z;
1212

1313
z = sizeof(unsigned);
14-
assert_d_eq(mallctl(cmd, &ret, &z, NULL, 0), 0,
14+
assert_d_eq(mallctl(cmd, (void *)&ret, &z, NULL, 0), 0,
1515
"Unexpected mallctl(\"%s\", ...) failure", cmd);
1616

1717
return (ret);
@@ -37,7 +37,7 @@ get_size_impl(const char *cmd, size_t ind)
3737
0, "Unexpected mallctlnametomib(\"%s\", ...) failure", cmd);
3838
mib[2] = ind;
3939
z = sizeof(size_t);
40-
assert_d_eq(mallctlbymib(mib, miblen, &ret, &z, NULL, 0),
40+
assert_d_eq(mallctlbymib(mib, miblen, (void *)&ret, &z, NULL, 0),
4141
0, "Unexpected mallctlbymib([\"%s\", %zu], ...) failure", cmd, ind);
4242

4343
return (ret);

test/integration/overflow.c

100644100755
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ TEST_BEGIN(test_overflow)
88
void *p;
99

1010
sz = sizeof(unsigned);
11-
assert_d_eq(mallctl("arenas.nhchunks", &nhchunks, &sz, NULL, 0), 0,
12-
"Unexpected mallctl() error");
11+
assert_d_eq(mallctl("arenas.nhchunks", (void *)&nhchunks, &sz, NULL, 0),
12+
0, "Unexpected mallctl() error");
1313

1414
miblen = sizeof(mib) / sizeof(size_t);
1515
assert_d_eq(mallctlnametomib("arenas.hchunk.0.size", mib, &miblen), 0,
1616
"Unexpected mallctlnametomib() error");
1717
mib[2] = nhchunks - 1;
1818

1919
sz = sizeof(size_t);
20-
assert_d_eq(mallctlbymib(mib, miblen, &max_size_class, &sz, NULL, 0), 0,
21-
"Unexpected mallctlbymib() error");
20+
assert_d_eq(mallctlbymib(mib, miblen, (void *)&max_size_class, &sz,
21+
NULL, 0), 0, "Unexpected mallctlbymib() error");
2222

2323
assert_ptr_null(malloc(max_size_class + 1),
2424
"Expected OOM due to over-sized allocation request");

0 commit comments

Comments
 (0)