This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: pointer comparison breaks Solaris' qsort
Jakub Jelinek <jakub@redhat.com> writes:
> On Tue, Jun 08, 2004 at 06:53:31AM -0300, Alexandre Oliva wrote:
>> This patch fixes a linker crash caused by inconsistent results being
>> returned by the function passed to qsort(). In certain cases, when it
>> returns the same value when comparing both a with b and b with a, the
>> qsort function may end up being called with a pointer that's not
>> within the bounds of the array passed to qsort().
>
> That is a Solaris bug then.
No, undefined behaviour.
> http://www.opengroup.org/onlinepubs/009695399/functions/qsort.html
> is clear on this, for each argument p to the compar function:
> ((char *)p - (char *)base) % width == 0
> (char *)p >= (char *)base
> (char *)p < (char *)base + nel * width
If the comparison function does not conform to the specs in the standard
then the qsort function is not bound by these specs either.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."