@@ -4510,25 +4510,23 @@ static int php_pgsql_convert_match(const zend_string *str, const char *regex , s
4510
4510
/* {{{ php_pgsql_add_quote
4511
4511
* add quotes around string.
4512
4512
*/
4513
- static int php_pgsql_add_quotes (zval * src , bool should_free )
4513
+ static zend_string * php_pgsql_add_quotes (zend_string * src )
4514
4514
{
4515
4515
smart_str str = {0 };
4516
-
4517
- assert (Z_TYPE_P (src ) == IS_STRING );
4518
- assert (should_free == 1 || should_free == 0 );
4516
+ zend_string * result ;
4519
4517
4520
4518
smart_str_appendc (& str , 'E' );
4521
4519
smart_str_appendc (& str , '\'' );
4522
- smart_str_appendl (& str , Z_STRVAL_P ( src ), Z_STRLEN_P ( src ) );
4520
+ smart_str_append (& str , src );
4523
4521
smart_str_appendc (& str , '\'' );
4524
4522
smart_str_0 (& str );
4525
4523
4526
- if ( should_free ) {
4527
- zval_ptr_dtor ( src );
4528
- }
4529
- ZVAL_NEW_STR ( src , str . s );
4524
+ result = zend_string_dup ( str . s , false);
4525
+ /* Free source and smart string */
4526
+ zend_string_release ( src );
4527
+ smart_str_free ( & str );
4530
4528
4531
- return SUCCESS ;
4529
+ return result ;
4532
4530
}
4533
4531
/* }}} */
4534
4532
@@ -4741,8 +4739,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4741
4739
if (php_pgsql_convert_match (Z_STR_P (val ), REGEX1 , sizeof (REGEX1 )- 1 , 1 ) == FAILURE ) {
4742
4740
err = 1 ;
4743
4741
} else {
4744
- ZVAL_STRING (& new_val , Z_STRVAL_P (val ));
4745
- php_pgsql_add_quotes (& new_val , 1 );
4742
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4746
4743
}
4747
4744
}
4748
4745
else {
@@ -4809,8 +4806,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4809
4806
/* better to use PGSQLescapeLiteral since PGescapeStringConn does not handle special \ */
4810
4807
ZSTR_LEN (str ) = PQescapeStringConn (pg_link , ZSTR_VAL (str ), Z_STRVAL_P (val ), Z_STRLEN_P (val ), NULL );
4811
4808
str = zend_string_truncate (str , ZSTR_LEN (str ), 0 );
4812
- ZVAL_NEW_STR (& new_val , str );
4813
- php_pgsql_add_quotes (& new_val , 1 );
4809
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (str ));
4814
4810
}
4815
4811
break ;
4816
4812
@@ -4896,8 +4892,9 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4896
4892
err = 1 ;
4897
4893
}
4898
4894
else {
4899
- ZVAL_STRINGL (& new_val , Z_STRVAL_P (val ), Z_STRLEN_P (val ));
4900
- php_pgsql_add_quotes (& new_val , 1 );
4895
+ zend_string * tmp_zstr = php_pgsql_add_quotes (Z_STR_P (val ));
4896
+ ZVAL_STRINGL (& new_val , ZSTR_VAL (tmp_zstr ), ZSTR_LEN (tmp_zstr ));
4897
+ zend_string_release (tmp_zstr );
4901
4898
}
4902
4899
#undef REGEX0
4903
4900
#undef REGEX1
@@ -4932,8 +4929,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4932
4929
if (php_pgsql_convert_match (Z_STR_P (val ), REGEX0 , sizeof (REGEX0 )- 1 , 1 ) == FAILURE ) {
4933
4930
err = 1 ;
4934
4931
} else {
4935
- ZVAL_STRING (& new_val , Z_STRVAL_P (val ));
4936
- php_pgsql_add_quotes (& new_val , 1 );
4932
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4937
4933
}
4938
4934
#undef REGEX0
4939
4935
}
@@ -4965,8 +4961,9 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4965
4961
err = 1 ;
4966
4962
}
4967
4963
else {
4968
- ZVAL_STRINGL (& new_val , Z_STRVAL_P (val ), Z_STRLEN_P (val ));
4969
- php_pgsql_add_quotes (& new_val , 1 );
4964
+ zend_string * tmp_zstr = php_pgsql_add_quotes (Z_STR_P (val ));
4965
+ ZVAL_STRINGL (& new_val , ZSTR_VAL (tmp_zstr ), ZSTR_LEN (tmp_zstr ));
4966
+ zend_string_release (tmp_zstr );
4970
4967
}
4971
4968
#undef REGEX0
4972
4969
}
@@ -4998,8 +4995,9 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4998
4995
err = 1 ;
4999
4996
}
5000
4997
else {
5001
- ZVAL_STRINGL (& new_val , Z_STRVAL_P (val ), Z_STRLEN_P (val ));
5002
- php_pgsql_add_quotes (& new_val , 1 );
4998
+ zend_string * tmp_zstr = php_pgsql_add_quotes (Z_STR_P (val ));
4999
+ ZVAL_STRINGL (& new_val , ZSTR_VAL (tmp_zstr ), ZSTR_LEN (tmp_zstr ));
5000
+ zend_string_release (tmp_zstr );
5003
5001
}
5004
5002
#undef REGEX0
5005
5003
}
@@ -5077,8 +5075,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
5077
5075
err = 1 ;
5078
5076
}
5079
5077
else {
5080
- ZVAL_STRING (& new_val , Z_STRVAL_P (val ));
5081
- php_pgsql_add_quotes (& new_val , 1 );
5078
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
5082
5079
}
5083
5080
#undef REGEX0
5084
5081
}
@@ -5105,14 +5102,16 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
5105
5102
else {
5106
5103
unsigned char * tmp ;
5107
5104
size_t to_len ;
5105
+ zend_string * tmp_zstr ;
5108
5106
smart_str s = {0 };
5109
5107
tmp = PQescapeByteaConn (pg_link , (unsigned char * )Z_STRVAL_P (val ), Z_STRLEN_P (val ), & to_len );
5110
- ZVAL_STRINGL ( & new_val , ( char * )tmp , to_len - 1 ); /* PQescapeBytea's to_len includes additional '\0' */
5108
+ tmp_zstr = zend_string_init (( char * )tmp , to_len - 1 , false ); /* PQescapeBytea's to_len includes additional '\0' */
5111
5109
PQfreemem (tmp );
5112
- php_pgsql_add_quotes (& new_val , 1 );
5113
- smart_str_appendl (& s , Z_STRVAL (new_val ), Z_STRLEN (new_val ));
5110
+ /* tmp_zstr is freed by php_pgsql_add_quotes() */
5111
+ tmp_zstr = php_pgsql_add_quotes (tmp_zstr );
5112
+ smart_str_append (& s , tmp_zstr );
5114
5113
smart_str_0 (& s );
5115
- zval_ptr_dtor ( & new_val );
5114
+ zend_string_release ( tmp_zstr );
5116
5115
ZVAL_NEW_STR (& new_val , s .s );
5117
5116
}
5118
5117
break ;
@@ -5151,8 +5150,9 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
5151
5150
err = 1 ;
5152
5151
}
5153
5152
else {
5154
- ZVAL_STRINGL (& new_val , Z_STRVAL_P (val ), Z_STRLEN_P (val ));
5155
- php_pgsql_add_quotes (& new_val , 1 );
5153
+ zend_string * tmp_zstr = php_pgsql_add_quotes (Z_STR_P (val ));
5154
+ ZVAL_STRINGL (& new_val , ZSTR_VAL (tmp_zstr ), ZSTR_LEN (tmp_zstr ));
5155
+ zend_string_release (tmp_zstr );
5156
5156
}
5157
5157
#undef REGEX0
5158
5158
}
0 commit comments