com php-src: Fix string increment: Zend/zend_operators.c tests/lang/operators/preinc_variationStr.phpt
| From: | Nikita Popov | Date: | Fri, 05 Sep 2014 10:45:42 +0000 |
| Subject: | com php-src: Fix string increment: Zend/zend_operators.c tests/lang/operators/preinc_variationStr.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-81439@lists.php.net to get a copy of this message | ||
Commit: 828fe353817c78cec2ceb7c42ff0644069f46ba7
Author: Nikita Popov <nikic@php.net> Fri, 5 Sep 2014 12:44:51 +0200
Parents: 9a420f0361243e0aa42f93fd996c8f2f133c20cc
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=828fe353817c78cec2ceb7c42ff0644069f46ba7
Log:
Fix string increment
Changed paths:
M Zend/zend_operators.c
M tests/lang/operators/preinc_variationStr.phpt
Diff:
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index e4fdaa6..2e48c15 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -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);
diff --git a/tests/lang/operators/preinc_variationStr.phpt
b/tests/lang/operators/preinc_variationStr.phpt
index 010a237..4e60705 100644
--- a/tests/lang/operators/preinc_variationStr.phpt
+++ b/tests/lang/operators/preinc_variationStr.phpt
@@ -1,22 +1,23 @@
---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"
-);
-
-
-foreach ($strVals as $strVal) {
- echo "--- testing: '$strVal' ---\n";
- var_dump(++$strVal);
-}
-
-?>
-===DONE===
---EXPECT--
+--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"
-===DONE===
+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===