]> granicus.if.org Git - php/commitdiff
Fix string increment
authorNikita Popov <nikic@php.net>
Fri, 5 Sep 2014 10:44:51 +0000 (12:44 +0200)
committerNikita Popov <nikic@php.net>
Fri, 5 Sep 2014 10:45:42 +0000 (12:45 +0200)
Zend/zend_operators.c
tests/lang/operators/preinc_variationStr.phpt

index e4fdaa6f9e46153103071e66226d72a519f74079..2e48c154e91561d5e45728aa1ada5a31cea3e035 100644 (file)
@@ -2023,7 +2023,7 @@ static void increment_string(zval *str) /* {{{ */
        }
        s = Z_STRVAL_P(str);
 
-       while (pos >= 0) {
+       do {
                ch = s[pos];
                if (ch >= 'a' && ch <= 'z') {
                        if (ch == 'z') {
@@ -2059,8 +2059,7 @@ static void increment_string(zval *str) /* {{{ */
                if (carry == 0) {
                        break;
                }
-               pos--;
-       }
+       } while (pos-- > 0);
 
        if (carry) {
                t = zend_string_alloc(Z_STRLEN_P(str)+1, 0);
index 010a237034d7272f3ec03df6649d7ea3e40f7380..4e607057f716b3b357c25894fc740975b63e9fe6 100644 (file)
@@ -1,22 +1,23 @@
---TEST--\r
-Test ++N operator : various numbers as strings\r
---FILE--\r
-<?php\r
-\r
-$strVals = array(\r
-   "0","65","-44", "1.2", "-7.7", "abc", "123abc", "123e5", "123e5xyz", " 123abc", "123 abc", "123abc ", "3.4a",\r
-   "a5.9"\r
-);\r
-\r
-\r
-foreach ($strVals as $strVal) {\r
-   echo "--- testing: '$strVal' ---\n";\r
-   var_dump(++$strVal);\r
-}\r
-   \r
-?>\r
-===DONE===\r
---EXPECT--\r
+--TEST--
+Test ++N operator : various numbers as strings
+--FILE--
+<?php
+
+$strVals = array(
+    "0","65","-44", "1.2", "-7.7",
+    "abc", "123abc", "123e5", "123e5xyz", " 123abc", "123 abc", "123abc ", "3.4a", "a5.9",
+    "z", "az", "zz", "Z", "AZ", "ZZ", "9z", "19z", "99z",
+);
+
+
+foreach ($strVals as $strVal) {
+    echo "--- testing: '$strVal' ---\n";
+    var_dump(++$strVal);
+}
+
+?>
+===DONE===
+--EXPECT--
 --- testing: '0' ---
 int(1)
 --- testing: '65' ---
@@ -44,5 +45,23 @@ string(7) "123abc "
 --- testing: '3.4a' ---
 string(4) "3.4b"
 --- testing: 'a5.9' ---
-string(4) "a5.0"\r
-===DONE===\r
+string(4) "a5.0"
+--- testing: 'z' ---
+string(2) "aa"
+--- testing: 'az' ---
+string(2) "ba"
+--- testing: 'zz' ---
+string(3) "aaa"
+--- testing: 'Z' ---
+string(2) "AA"
+--- testing: 'AZ' ---
+string(2) "BA"
+--- testing: 'ZZ' ---
+string(3) "AAA"
+--- testing: '9z' ---
+string(3) "10a"
+--- testing: '19z' ---
+string(3) "20a"
+--- testing: '99z' ---
+string(4) "100a"
+===DONE===