PHP 4.0 Bug #8195: strncasecmp returns incorrect value

From: Date: Mon, 11 Dec 2000 21:08:35 +0000
Subject: PHP 4.0 Bug #8195: strncasecmp returns incorrect value
Groups: php.dev 
Request: Send a blank email to php-dev+get-40896@lists.php.net to get a copy of this message
From: kway@wgate.com Operating system: FreeBSD 4.2 PHP version: 4.0 Latest CVS (11/12/2000) PHP Bug Type: Scripting Engine problem Bug description: strncasecmp returns incorrect value strncasecmp returns len1 - len2, regardless of how many characters we wanted to compare, thus strncasecmp('foo', 'foosomethingelse', 3) would return -13 instead of 0, as would be correct. The following patch fixes this problem properly: Index: zend_operators.c =================================================================== RCS file: /repository/Zend/zend_operators.c,v retrieving revision 1.88 diff -u -5 -r1.88 zend_operators.c --- zend_operators.c 2000/11/21 22:41:49 1.88 +++ zend_operators.c 2000/12/11 21:06:29 @@ -1561,11 +1561,11 @@ if (c1 != c2) { return c1 - c2; } } - return len1 - len2; + return MIN(length, len1) - MIN(length, len2); } ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2) { -- Edit Bug report at: http://bugs.php.net/?id=8195&edit=1

« previous php.dev (#40896) next »