From owner-freebsd-bugs Sun Sep 15 23:40: 5 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5607337B401 for ; Sun, 15 Sep 2002 23:40:04 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id DE96043E6E for ; Sun, 15 Sep 2002 23:40:03 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g8G6e3JU073175 for ; Sun, 15 Sep 2002 23:40:03 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g8G6e35s073174; Sun, 15 Sep 2002 23:40:03 -0700 (PDT) Date: Sun, 15 Sep 2002 23:40:03 -0700 (PDT) Message-Id: <200209160640.g8G6e35s073174@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Gregory Bond Subject: Re: kern/42818: qsort can only sort up to 6 element for structure Reply-To: Gregory Bond Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR kern/42818; it has been noted by GNATS. From: Gregory Bond To: j_guojun@lbl.gov Cc: FreeBSD-gnats-submit@FreeBSD.ORG Subject: Re: kern/42818: qsort can only sort up to 6 element for structure Date: Mon, 16 Sep 2002 16:30:13 +1000 The bug is in your program. To quote qsort(3): The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. Your comparison function returns 0 or 1 only. Perhaps you are being confused by the C++/STL comparison objects? Modifying your comparison fn to the following makes it work: int smaller(const void *i1, const void *i2) { if (*(int*)i1 < *(int*)i2) return -1; return *(int*)i1 > *(int*)i2; } The fact that your test program seems to work for these test cases on Solaris and Linux is a simple coincidence, and depends on fine internal details of the sort algorithm on those systems. There will probably be other cases where the Linux/Solaris qsort() will also fail. This PR can be closed. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message