Bug #3556 Updated: strcasecmp() compares lengths instead of string contents
| From: | Bug Database | Date: | Sun, 05 Mar 2000 20:04:57 +0000 |
| Subject: | Bug #3556 Updated: strcasecmp() compares lengths instead of string contents | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-16426@lists.php.net to get a copy of this message | ||
ID: 3556
Updated by: hholzgra
Reported By: erw.dongen@wxs.nl
Status: Analyzed
Bug Type: Misbehaving function
Assigned To:
Comments:
no, it isn't !!!
strcasecmp("B","AAA") should be equal to strcmp("B","AAA")
at least in the results sign
the code for zend_binary_strcasecmp()
in Zend/zend_operators.c is broken, the following diff
should fix it:
--- zend_operators.c 2000/03/01 13:59:51 1.53
+++ zend_operators.c 2000/03/05 19:56:43
@@ -1256,20 +1256,19 @@
ZEND_API int zend_binary_strcasecmp(char *s1, uint len1, char *s2, uint len2)
{
unsigned char c1 = 0, c2 = 0;
+ int len;
- if (len1 != len2 || !len1) {
- return len1 - len2;
- }
+ len = MIN(len1,len2);
- while (len1--) {
+ while (len--) {
c1 = tolower(*s1++);
c2 = tolower(*s2++);
if (c1 != c2) {
- break;
+ return c1 - c2;
}
}
- return c1 - c2;
+ return len1 - len2;
}
Full Bug description available at: http://bugs.php.net/?id=3556