[postgis-tickets] [PostGIS] #4093: Inconsistent results from qsort callback

PostGIS trac at osgeo.org
Mon May 21 12:46:26 PDT 2018


#4093: Inconsistent results from qsort callback
---------------------+---------------------------
 Reporter:  yugr     |      Owner:  pramsey
     Type:  defect   |     Status:  new
 Priority:  medium   |  Milestone:  PostGIS 2.4.5
Component:  postgis  |    Version:  2.4.x
 Keywords:           |
---------------------+---------------------------
 Hi,

 qsort callbacks struct_cmp_by_measure and cmpfunc may return invalid
 result when arguments are swapped. Such bugs may causes inconsistent order
 or even crashes in some qsort implementations
 (https://bugzilla.samba.org/show_bug.cgi?id=3959).

 The issue has been detected when running standard testsuite under
 SortChecker (https://github.com/yugr/sortcheck):
   lt-cu_tester[425]: qsort: comparison function is not symmetric
 (comparison function 0x7f1913a75ef0
 (/build/postgis-2.2.1+dfsg/liblwgeom/.libs/liblwgeom-2.2.so.5.0.0+0x10ef0),
 called from 0x7f1913a77456
 (/build/postgis-2.2.1+dfsg/liblwgeom/.libs/liblwgeom-2.2.so.5.0.0+0x12456),
 cmdline is "/build/postgis-2.2.1+dfsg/liblwgeom/cunit/.libs/lt-cu_tester")

 The fix is to replace
         return ( ia->themeasure>ib->themeasure ) ? 1 : -1;
 with
         return ( ia->themeasure>ib->themeasure ) ? 1 : (
 ia->themeasure<ib->themeasure ) ? -1 : 0;
 and
                 return  (v1>v2 ) ? 1 : -1;
 with
                 return  (v1>v2 ) ? 1 : (v1<v2) ? -1 : 0;

-- 
Ticket URL: <https://trac.osgeo.org/postgis/ticket/4093>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-tickets mailing list