php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40848 compiler optimization bug randomizes array sorting
Submitted: 2007-03-18 20:12 UTC Modified: 2007-03-18 20:25 UTC
From: wez@php.net Assigned:
Status: Closed Package: Arrays related
PHP Version: 5.2.1 OS: Solaris
Private report: No CVE-ID: None
 [2007-03-18 20:12 UTC] 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;
        }



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-18 20:25 UTC] wez@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 06:01:30 2024 UTC