[PATCH 0/5] Fix qsort comparison functions

Yury Gribov y.gribov@samsung.com
Thu Dec 17 08:55:00 GMT 2015


Hi all,

This patchset fixes bugs in comparison functions used in qsort(3). 
Standard requires comparison functions to satisfy certain 
symmetry/transitivity axioms ("total ordering" in 
http://pubs.opengroup.org/onlinepubs/009695399/functions/qsort.html). 
Violation triggers undefined behavior which can e.g. cause qsort to 
produce invalid results (or even crash - check 
https://bugzilla.samba.org/show_bug.cgi?id=3959).

Most of the patches are pretty obvious except for no. 3 for which I was 
failed to devise a behavior-preserving fix.  I've Cc-ed the original 
authors in hope they'll be able to help.

I've verified all patches on x86_64-pc-linux-gnu (bootstrap + regression 
test).

NB: Bugs were found with SortChecker tool 
(https://github.com/yugr/sortcheck).

/Yury



More information about the Gcc-patches mailing list