Re: PHP 4.0 Bug #8383: array_unique() causes core dump

From: Date: Sat, 23 Dec 2000 12:41:07 +0000
Subject: Re: PHP 4.0 Bug #8383: array_unique() causes core dump
References: 1 2  Groups: php.dev 
Request: Send a blank email to php-dev+get-42170@lists.php.net to get a copy of this message
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 Reason I changed it, was that I didn't like what happened if I did say array_unique(array(0, "a", "b")); I did the same for array_intersect and array_diff too. There are other functions like asort() that does zend_hash_sort(target_hash, qsort, array_data_compare,0) I think they have the same problem. If they do, they should probably use array_type_data_compare instead. According to the description of array_data_compare in array.c numbers are always smaller than strings, but array_data_compare has been changed so that this is not the case any more, that's why I put in array_type_data_compare. Actually it might be that array_data_compare is useless as it is. Stig

« previous php.dev (#42170) next »