Re: [PHP-DEV] PHP 4.0 Bug #8383: array_unique() causes core dump From: Stig Venaas (Stig.Venaas <email protected>)
Date: 12/23/00

On Sat, Dec 23, 2000 at 01:41:07PM +0100, Stig Venaas wrote:
> On Sat, Dec 23, 2000 at 01:26:07AM +0100, Sascha Schumann wrote:
> > > array_unique(array("socket", "370", "99", "3d"));
> >
> > With the above input, qsort sees this:
> >
> > "socket" > "3d" (due to string comparison)
> > ^ "3d" > "370" (string)
> > ^ "370" > "99" (int)
> > ^ "99" > "3d" (string)
> >
> > That violates the rule "a > b ^ b > c => a > c". Solaris'
> > qsort does not like that and causes a segfault.

As I thought, other array sorting functions are broken. For instance
sort() uses qsort with array_data_compare, the result is segfault on
Solaris. Since array_data_compare isn't a transitive relation, it
doesn't define a order. On Linux I get:

$a = array("socket", "370", "99", "3d");
sort($a);

resulting in $a = array(370, "3d", 99, "socket");

and

$a = array("3d","socket", "370", "99");
sort($a);

resulting in $a = array("3d", 99, 370, "socket");

this wouldn't happen with a real ordering. I suggest using
array_type_data_compare(), the result would then in both
cases be: array(99, 370, "3d", "socket") and no segfault on
Solaris.

Stig

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>