Date: Sun, 15 Sep 2002 23:40:03 -0700 (PDT) From: Gregory Bond <gnb@itga.com.au> To: freebsd-bugs@FreeBSD.org Subject: Re: kern/42818: qsort can only sort up to 6 element for structure Message-ID: <200209160640.g8G6e35s073174@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/42818; it has been noted by GNATS. From: Gregory Bond <gnb@itga.com.au> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200209160640.g8G6e35s073174>