From 828fe353817c78cec2ceb7c42ff0644069f46ba7 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 5 Sep 2014 12:44:51 +0200 Subject: [PATCH] Fix string increment --- Zend/zend_operators.c | 5 +- tests/lang/operators/preinc_variationStr.phpt | 61 ++++++++++++------- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index e4fdaa6f9e..2e48c154e9 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 010a237034..4e607057f7 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-- - -===DONE=== ---EXPECT-- +--TEST-- +Test ++N operator : various numbers as strings +--FILE-- + +===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=== -- 2.50.1