@@ -1716,7 +1716,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
1716
1716
}
1717
1717
1718
1718
if (new_len >= alloc_len ) {
1719
- alloc_len = zend_safe_address_guarded (2 , new_len , alloc_len );
1719
+ alloc_len = zend_safe_address_guarded (2 , new_len , 0 );
1720
1720
if (result == NULL ) {
1721
1721
result = zend_string_alloc (alloc_len , 0 );
1722
1722
} else {
@@ -1802,14 +1802,12 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
1802
1802
result = zend_string_copy (subject_str );
1803
1803
break ;
1804
1804
}
1805
- new_len = result_len + subject_len - last_end_offset ;
1806
- if (new_len >= alloc_len ) {
1807
- alloc_len = new_len ; /* now we know exactly how long it is */
1808
- if (NULL != result ) {
1809
- result = zend_string_realloc (result , alloc_len , 0 );
1810
- } else {
1811
- result = zend_string_alloc (alloc_len , 0 );
1812
- }
1805
+ /* now we know exactly how long it is */
1806
+ alloc_len = result_len + subject_len - last_end_offset ;
1807
+ if (NULL != result ) {
1808
+ result = zend_string_realloc (result , alloc_len , 0 );
1809
+ } else {
1810
+ result = zend_string_alloc (alloc_len , 0 );
1813
1811
}
1814
1812
/* stick that last bit of string on our output */
1815
1813
memcpy (ZSTR_VAL (result ) + result_len , piece , subject_len - last_end_offset );
@@ -1956,7 +1954,7 @@ static zend_string *php_pcre_replace_func_impl(pcre_cache_entry *pce, zend_strin
1956
1954
ZEND_ASSERT (eval_result );
1957
1955
new_len = zend_safe_address_guarded (1 , ZSTR_LEN (eval_result ), new_len );
1958
1956
if (new_len >= alloc_len ) {
1959
- alloc_len = zend_safe_address_guarded (2 , new_len , alloc_len );
1957
+ alloc_len = zend_safe_address_guarded (2 , new_len , 0 );
1960
1958
if (result == NULL ) {
1961
1959
result = zend_string_alloc (alloc_len , 0 );
1962
1960
} else {
@@ -2013,14 +2011,12 @@ static zend_string *php_pcre_replace_func_impl(pcre_cache_entry *pce, zend_strin
2013
2011
result = zend_string_copy (subject_str );
2014
2012
break ;
2015
2013
}
2016
- new_len = result_len + subject_len - last_end_offset ;
2017
- if (new_len >= alloc_len ) {
2018
- alloc_len = new_len ; /* now we know exactly how long it is */
2019
- if (NULL != result ) {
2020
- result = zend_string_realloc (result , alloc_len , 0 );
2021
- } else {
2022
- result = zend_string_alloc (alloc_len , 0 );
2023
- }
2014
+ /* now we know exactly how long it is */
2015
+ alloc_len = result_len + subject_len - last_end_offset ;
2016
+ if (NULL != result ) {
2017
+ result = zend_string_realloc (result , alloc_len , 0 );
2018
+ } else {
2019
+ result = zend_string_alloc (alloc_len , 0 );
2024
2020
}
2025
2021
/* stick that last bit of string on our output */
2026
2022
memcpy (ZSTR_VAL (result ) + result_len , piece , subject_len - last_end_offset );
0 commit comments