#29075 [Ver->Ana]: strnatcmp('foo ', 'foo ') returns -1, should return 0

From: Date: Sun, 11 Jul 2004 20:41:22 +0000
Subject: #29075 [Ver->Ana]: strnatcmp('foo ', 'foo ') returns -1, should return 0
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-62064@lists.php.net to get a copy of this message
ID: 29075 Updated by: curt@php.net Reported By: oliver at burtchen dot com -Status: Verified +Status: Analyzed Bug Type: Strings related Operating System: * PHP Version: 4CVS, 5CVS New Comment: The problem is that spaces at the end of the string cause the ap and bp pointers to be looking at strlen+1 here is the patch to prevent that. Index: ext/standard/strnatcmp.c =================================================================== RCS file: /repository/php-src/ext/standard/strnatcmp.c,v retrieving revision 1.9 diff -u -r1.9 strnatcmp.c --- ext/standard/strnatcmp.c 16 Apr 2003 21:10:29 -0000 1.9 +++ ext/standard/strnatcmp.c 11 Jul 2004 20:38:30 -0000 @@ -153,13 +153,13 @@ return +1; ++ap; ++bp; - if (ap == aend && bp == bend) + if (ap >= aend && bp >= bend) /* The strings compare the same. Perhaps the caller will want to call strcmp to break the tie. */ return 0; - else if (ap == aend) + else if (ap >= aend) return -1; - else if (bp == bend) + else if (bp >= bend) return 1; } } Previous Comments: ------------------------------------------------------------------------ [2004-07-11 19:27:43] sniper@php.net See also bug #19795 (there doesn't seem to be any test case for this function..the one who fixes should add that too, I can't access CVS atm) ------------------------------------------------------------------------ [2004-07-09 17:23:12] oliver at burtchen dot com Description: ------------ strnatcmp('foo ', 'foo ') returns -1 and not 0 as expected. As far as I can see, it depends on the trailling whitespace. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29075&edit=1

« previous php.bugs (#62064) next »