Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
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&nbsp;
The core dump happens at the line ‘long long a = *((long long *)p1);’ when dereferencing the point.
Below is my test case. Thanks&nbsp;




#include <stdlib.h&gt;
#include <stdio.h&gt;



static int compare(const void *p1, const void *p2) {
&nbsp; &nbsp; long long a = *((long long *)p1);
&nbsp; &nbsp; long long b = *((long long *)p2);
&nbsp; &nbsp; if (a &gt; b) return 1;
&nbsp; &nbsp; if (a < b) return -1;
&nbsp; &nbsp; return 0;
}


int main(void) {
&nbsp; &nbsp; const size_t n = 20000000;
&nbsp; &nbsp; long long *arr = calloc(sizeof(long long), n);
&nbsp; &nbsp;
&nbsp; &nbsp; if (!arr) {
&nbsp; &nbsp; &nbsp; &nbsp; perror("malloc failed");
&nbsp; &nbsp; &nbsp; &nbsp; return 1;
&nbsp; &nbsp; }
&nbsp; &nbsp;
&nbsp; &nbsp; for (size_t i = 0; i < n; i++) {
&nbsp; &nbsp; &nbsp; &nbsp; arr[i] = i;
&nbsp; &nbsp; }
&nbsp; &nbsp;
&nbsp; &nbsp; printf("Sorting %zu elements...\n", n);
&nbsp; &nbsp; qsort(arr, n, sizeof(long long), compare);
&nbsp; &nbsp; printf("Sort completed successfully.\n");
&nbsp; &nbsp;
&nbsp; &nbsp; free(arr);
&nbsp; &nbsp; return 0;
}


------------------ Original ------------------
From: Rich Felker <dalias@...c.org&gt;
Date: Thu,Apr 9,2026 11:43 AM
To: Hankins <546824250@...com&gt;
Cc: musl <musl@...ts.openwall.com&gt;
Subject: Re: [musl] qsort core dump with 20,000,000 elements on 32-bit systems



On&nbsp;Thu,&nbsp;Apr&nbsp;09,&nbsp;2026&nbsp;at&nbsp;11:13:38AM&nbsp;+0800,&nbsp;Hankins&nbsp;wrote:
&gt;&nbsp;Hi,&nbsp;I've&nbsp;encountered&nbsp;a&nbsp;core&nbsp;dump&nbsp;when&nbsp;trying&nbsp;to&nbsp;sort&nbsp;an&nbsp;array&nbsp;of
&gt;&nbsp;20,000,000&nbsp;elements&nbsp;on&nbsp;32-bit&nbsp;systems.&nbsp;musl&nbsp;version&nbsp;is
&gt;&nbsp;1.2.4.
&gt;&nbsp;I&nbsp;would&nbsp;like&nbsp;to&nbsp;ask&nbsp;what&nbsp;the&nbsp;reason&nbsp;for&nbsp;this&nbsp;is.&nbsp;Thanks.
&gt;&nbsp;hankins

Can&nbsp;you&nbsp;please&nbsp;provide&nbsp;more&nbsp;details,&nbsp;ideally&nbsp;a&nbsp;minimal&nbsp;test&nbsp;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.