Re: PHP 4.0 Bug #8383: array_unique() causes core dump
| From: | Stig Venaas | Date: | Sat, 23 Dec 2000 20:19:54 +0000 |
| Subject: | Re: PHP 4.0 Bug #8383: array_unique() causes core dump | ||
| References: | 1 2 3 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-42183@lists.php.net to get a copy of this message | ||
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