Re: PHP 4.0 Bug #8383: array_unique() causes core dump
| From: | Stig Venaas | Date: | Thu, 28 Dec 2000 23:58:31 +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-42488@lists.php.net to get a copy of this message | ||
I keep replying to my own mails... (:
I've done some testing and also got a mail from Andrei regarding
related problems in array_diff().
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.
>
> Right, I see. Interesting problem, this might be a problem for someone
> doing sorting in PHP as well. I changed the code for array_unique, to
> use what I called array_type_data_compare instead of array_data_compare
> two months ago; after 4.0.3pl1 was released I think. It should fix this
> since it compares type first, so that numeric types are always smaller
> than strings. The order should then be:
>
> socket > 3d > 370 > 99
I'm wrong, I was thinking of 370 and 99 as numbers, but they are strings
but are still compared as numbers, so array_type_data_compare doesn't
fix it. I've now removed array_type_data_compare and am instead using
array_data_compare with compare_func set to SORT_STRING and not
SORT_REGULAR. I think this should solve the problem, but I could be
wrong. Please test latest CVS and let me know if there are still
problems.
Thanks for the bug report, and thanks for good help in debugging Sascha.
Stig