Bug #18313: elusive recursion-related crash
| From: | admin at finance-on dot net | Date: | Fri, 12 Jul 2002 12:49:16 +0000 |
| Subject: | Bug #18313: elusive recursion-related crash | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-13977@lists.php.net to get a copy of this message | ||
From: admin@finance-on.net
Operating system: linux, 2.4 kernel
PHP version: 4.2.1
PHP Bug Type: Reproducible crash
Bug description: elusive recursion-related crash
i am sorting an array of strings using uasort($a,'isoCompare').
the user function isoCompare, in its recursive variant, crashes randomly.
first, the support function charPower which remaps diacritical chars...
this one is ok.
function charPower
($ch,$charPowerCaseSensitive=FALSE,$charPowerReverseOrder=FALSE) {
$power = 0;
$char = ($charPowerCaseSensitive ? $ch : strtoupper($ch));
switch (ord($char)) {
case 232: $power = 10*ord(($charPowerCaseSensitive ? "c" :
"C")
case 200: $power = 10*ord("C")+3; break;
case 190: $power = 10*ord(($charPowerCaseSensitive ? "z" :
"Z")
case 174: $power = 10*ord("Z")+5; break;
case 185: $power = 10*ord(($charPowerCaseSensitive ? "s" :
"S")
case 169: $power = 10*ord("S")+5; break;
case 230: $power = 10*ord(($charPowerCaseSensitive ? "c" :
"C")
case 198: $power = 10*ord("C")+6; break;
case 240: $power = 10*ord(($charPowerCaseSensitive ? "d" :
"D")
case 208: $power = 10*ord("D")+5; break;
default: $power = 10*ord($char);
}
return ($charPowerReverseOrder ? ((-1)*$power) : $power);
} ;
now the recursive isoCompare...
function isoCompare ($s1,$s2) {
$len1 = strlen($s1);
$len2 = strlen($s2);
if ($len1==0 || $len2==0) {
$ret = $len1 - $len2;
if (!$ret) return 0;
else return $ret > 0 ? +1 : -1;
} ;
$c1 = charPower($s1);
$c2 = charPower($s2);
$power1 = charPower($c1) ;
$power2 = charPower($c2) ;
if ($power1==$power2) {
$ret = isoCompare(substr($s1,1), substr($s2,1));
return $ret;
} else {
$ret = $power1-$power2;
return $ret > 0 ? +1 : -1;
}
}
the iterative version works fine:
function isoCompare ($s1, $s2) {
global $isadmin;
$i = 0; $ret = 0;
while (!$ret) {
$len1 = strlen($s1);
$len2 = strlen($s2);
if ($len1 == 0 && $len2 == 0) $ret = 0;
elseif ($len1 == 0) $ret = 1;
elseif ($len2 == 0) $ret = -1 ;
else {
$power1 = charPower(substr($s1,0,1)) ;
$power2 = charPower(substr($s2,0,1)) ;
if ($power1 > $power2) $ret = 1;
elseif ($power2 > $power1) $ret = -1;
else {
$s1 = substr($s1,1);
$s2 = substr($s2,1);
} ;
} ;
} ; // while
return $ret;
} ;
my setup:
./configure \
--with-config-file-path=/usr/local/lib \
--with-zlib \
--with-mysql=/usr/local/mysql \
--with-exec-dir=/usr/local/safe_mode --enable-track-vars=yes \
--enable-magic-quotes=yes --disable-debug \
--with-pdflib \
--with-xml \
--with-sablot=/usr/local/lib \
--with-expat=/usr/local/lib \
--enable-sysvsem \
--enable-sysvshm \
--with-gd \
--with-iconv \
--with-curl=/usr/local/curl \
--with-apxs=/usr/local/apache/bin/apxs
--
Edit bug report at http://bugs.php.net/?id=18313&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=18313&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=18313&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=18313&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=18313&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=18313&r=support
Expected behavior: http://bugs.php.net/fix.php?id=18313&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=18313&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=18313&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=18313&r=globals