qsort bug?

forsyth%minster.york.ac.uk at nsfnet-relay.ac.uk forsyth%minster.york.ac.uk at nsfnet-relay.ac.uk
Sat Jul 22 01:14:21 AEST 1989


By accident, someone here wrote a qsort comparison function that was
inconsistent (it compared the pointers not the values, and different calls
to compare the same [to qsort] objects gave different results).
Naturally, the array of objects wasn't sorted correctly.  More disturbing,
it seems that the BSD(?) based qsort distributed with SunOS has the
unfortunate property that in such cases it can smash memory, probably
because it relies on the comparison function to produce a sentinel value,
and then doesn't keep checking for the end/start of the array thereafter.
(Of course, it presumably finds the sentinel in order to be able to do
that!) Is this a known bug or `feature'?

The v7 qsort.c does not do this; nor does the system V one (the v7 one
modified to use memcpy when appropriate).  Also, the comment in UCB qsort
claims that it runs faster, but that's not my experience on an admittedly
limited sample.  Has anyone tested this claim against v7 and sys5 qsort.c?



More information about the Comp.sys.sun mailing list