Skip to content

Commit 02264e0

Browse files
authored
Fix clang build error browser64.test_pthread_malloc. NFC (#25051)
A recent clang change started generating this warning/error: ``` test_pthread_malloc (test_browser.browser64.test_pthread_malloc) ... /usr/local/google/home/sbc/dev/wasm/emscripten/test/pthread/test_pthread_malloc.c:19:21: error: allocation of insufficient size '4' for type 'long' with size '8' [-Werror,-Walloc-size] 19 | mem[i] = (long*)malloc(4); | ^ 1 error generated. ``` Also simplify the test a little.
1 parent 84cfc10 commit 02264e0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

test/pthread/test_pthread_malloc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ static void *thread_start(void *arg) {
1616
long n = (long)arg;
1717
long *mem[N] = {};
1818
for (long i = 0; i < N; ++i) {
19-
mem[i] = (long*)malloc(4);
19+
mem[i] = (long*)malloc(sizeof(long));
2020
*mem[i] = n+i;
2121
}
2222
for (long i = 0; i < N; ++i) {
2323
long k = *mem[i];
2424
if (k != n+i) {
2525
emscripten_errf("Memory corrupted! mem[i]: %ld, i: %ld, n: %ld", k, i, n);
26-
pthread_exit((void*)1);
26+
return (void*)1;
2727
}
2828

2929
assert(*mem[i] == n+i);
3030
free(mem[i]);
3131
}
3232
emscripten_outf("Worker with task number %ld finished", n);
33-
pthread_exit(0);
33+
return (void*)0;
3434
}
3535

3636
int main() {
@@ -40,9 +40,9 @@ int main() {
4040
}
4141
int result = 0;
4242
for (int i = 0; i < NUM_THREADS; ++i) {
43-
int res = 0;
43+
int res = 99;
4444
pthread_join(thr[i], (void**)&res);
45-
result += res;
45+
assert(res == 0);
4646
}
4747
printf("Test finished with result %d\n", result);
4848
assert(result == 0);

0 commit comments

Comments
 (0)