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