]> granicus.if.org Git - php/commitdiff
correct fix to the natcmp_ex
authorAnatol Belski <ab@php.net>
Mon, 15 Sep 2014 10:54:46 +0000 (12:54 +0200)
committerAnatol Belski <ab@php.net>
Mon, 15 Sep 2014 10:58:46 +0000 (12:58 +0200)
Till now the actualy length diff between the strings was under
circumstances returned. Whereby for a compare function only return
values of (1, 0, -1) make sense. Thus the old behavior isn't
present anymore, natcmp_ex now behaves as a standard compare function.

ext/standard/strnatcmp.c
ext/standard/tests/strings/strnatcasecmp_variation1.phpt

index 7b3826b5befb8de481accf3bdf08f61ccfbcd5cf..de6f7273430609d89d8e294bd29aecb1fab3ebe7 100644 (file)
@@ -109,23 +109,7 @@ PHPAPI int strnatcmp_ex(char const *a, size_t a_len, char const *b, size_t b_len
        short leading = 1;
 
        if (a_len == 0 || b_len == 0) {
-               result = 0;
-
-               if (a_len > b_len) {
-                       if (a_len - b_len <= INT_MAX) {
-                               result = (int)(a_len - b_len);
-                       } else {
-                               result = 1;
-                       }
-               } else {
-                       if (b_len - a_len <= (size_t)(-INT_MIN)) {
-                               result = -(int)(b_len - a_len);
-                       } else {
-                               result = -1;
-                       }
-               }
-
-               return result;
+               return (a_len == b_len ? 0 : (a_len > b_len ? 1 : -1));
        }
 
        ap = a;
index fb0fb79ae5ce96c046bfee7c98bae3773968ec19..e74f6b73e9a6dfe075a7681af8e4c7c56587eb12 100644 (file)
@@ -48,8 +48,8 @@ str_dump($a, $b);
 --EXPECT--
 *** Testing strnatcasecmp() : variation ***
 int(1)
-int(6)
-int(-2)
+int(1)
+int(-1)
 int(-1)
 int(0)
 int(0)