|
|
Message-ID: <tencent_470492C417CBCAED6E438A3E1EDB8C83EA05@qq.com>
Date: Thu, 9 Apr 2026 15:21:49 +0800
From: "Hankins" <546824250@...com>
To: "Rich Felker" <dalias@...c.org>
Cc: "musl" <musl@...ts.openwall.com>
Subject: Re: qsort core dump with 20,000,000 elements on 32-bit systems
Sorry, I should have described it in more detail.
I discovered the issue while testing on a 32-bit system: when the number of elements sorted by qsort exceeds 18454930, a core dump occurs; otherwise, it does not
The core dump happens at the line ‘long long a = *((long long *)p1);’ when dereferencing the point.
Below is my test case. Thanks
#include <stdlib.h>
#include <stdio.h>
static int compare(const void *p1, const void *p2) {
long long a = *((long long *)p1);
long long b = *((long long *)p2);
if (a > b) return 1;
if (a < b) return -1;
return 0;
}
int main(void) {
const size_t n = 20000000;
long long *arr = calloc(sizeof(long long), n);
if (!arr) {
perror("malloc failed");
return 1;
}
for (size_t i = 0; i < n; i++) {
arr[i] = i;
}
printf("Sorting %zu elements...\n", n);
qsort(arr, n, sizeof(long long), compare);
printf("Sort completed successfully.\n");
free(arr);
return 0;
}
------------------ Original ------------------
From: Rich Felker <dalias@...c.org>
Date: Thu,Apr 9,2026 11:43 AM
To: Hankins <546824250@...com>
Cc: musl <musl@...ts.openwall.com>
Subject: Re: [musl] qsort core dump with 20,000,000 elements on 32-bit systems
On Thu, Apr 09, 2026 at 11:13:38AM +0800, Hankins wrote:
> Hi, I've encountered a core dump when trying to sort an array of
> 20,000,000 elements on 32-bit systems. musl version is
> 1.2.4.
> I would like to ask what the reason for this is. Thanks.
> hankins
Can you please provide more details, ideally a minimal test case?
Rich
Content of type "text/html" skipped
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.