#40848 [Opn->Csd]: compiler optimization bug randomizes array sorting

From: Date: Sun, 18 Mar 2007 20:25:46 +0000
Subject: #40848 [Opn->Csd]: compiler optimization bug randomizes array sorting
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-110482@lists.php.net to get a copy of this message
 ID:               40848
 Updated by:       wez@php.net
 Reported By:      wez@php.net
-Status:           Open
+Status:           Closed
 Bug Type:         Arrays related
 Operating System: Solaris
 PHP Version:      5.2.1
 New Comment:

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------

[2007-03-18 20:12:02] wez@php.net

Description:
------------
Because the wrong type is used for the return value from the qsort
callback function, the compiler screws up the actual return value,
causing the sort to be incorrect.

The following diff avoids the bug by explicitly return the "right"
values:

cvs diff: Diffing .
Index: array.c
===================================================================
RCS file: /repository/php-src/ext/standard/array.c,v
retrieving revision 1.308.2.21.2.25
diff -u -p -r1.308.2.21.2.25 array.c
--- array.c     16 Mar 2007 19:38:58 -0000      1.308.2.21.2.25
+++ array.c     18 Mar 2007 20:03:36 -0000
@@ -596,7 +596,7 @@ static int array_user_compare(const void
                convert_to_long_ex(&retval_ptr);
                retval = Z_LVAL_P(retval_ptr);
                zval_ptr_dtor(&retval_ptr);
-               return retval;
+               return retval < 0 ? -1 : retval > 0 ? 1 : 0;
        } else {
                return 0;
        }




------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=40848&edit=1


Thread (2 messages)

« previous php.bugs (#110482) next »