@@ -4510,25 +4510,17 @@ 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
4516
4517
- assert (Z_TYPE_P (src ) == IS_STRING );
4518
- assert (should_free == 1 || should_free == 0 );
4519
-
4520
4517
smart_str_appendc (& str , 'E' );
4521
4518
smart_str_appendc (& str , '\'' );
4522
- smart_str_appendl (& str , Z_STRVAL_P ( src ), Z_STRLEN_P ( src ) );
4519
+ smart_str_append (& str , src );
4523
4520
smart_str_appendc (& str , '\'' );
4524
4521
smart_str_0 (& str );
4525
4522
4526
- if (should_free ) {
4527
- zval_ptr_dtor (src );
4528
- }
4529
- ZVAL_NEW_STR (src , str .s );
4530
-
4531
- return SUCCESS ;
4523
+ return str .s ;
4532
4524
}
4533
4525
/* }}} */
4534
4526
@@ -4741,8 +4733,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4741
4733
if (php_pgsql_convert_match (Z_STR_P (val ), REGEX1 , sizeof (REGEX1 )- 1 , 1 ) == FAILURE ) {
4742
4734
err = 1 ;
4743
4735
} else {
4744
- ZVAL_STRING (& new_val , Z_STRVAL_P (val ));
4745
- php_pgsql_add_quotes (& new_val , 1 );
4736
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4746
4737
}
4747
4738
}
4748
4739
else {
@@ -4809,8 +4800,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4809
4800
/* better to use PGSQLescapeLiteral since PGescapeStringConn does not handle special \ */
4810
4801
ZSTR_LEN (str ) = PQescapeStringConn (pg_link , ZSTR_VAL (str ), Z_STRVAL_P (val ), Z_STRLEN_P (val ), NULL );
4811
4802
str = zend_string_truncate (str , ZSTR_LEN (str ), 0 );
4812
- ZVAL_NEW_STR (& new_val , str );
4813
- php_pgsql_add_quotes (& new_val , 1 );
4803
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (str ));
4814
4804
}
4815
4805
break ;
4816
4806
@@ -4896,8 +4886,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4896
4886
err = 1 ;
4897
4887
}
4898
4888
else {
4899
- ZVAL_STR (& new_val , Z_STR_P (val ));
4900
- php_pgsql_add_quotes (& new_val , 1 );
4889
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4901
4890
}
4902
4891
#undef REGEX0
4903
4892
#undef REGEX1
@@ -4932,8 +4921,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4932
4921
if (php_pgsql_convert_match (Z_STR_P (val ), REGEX0 , sizeof (REGEX0 )- 1 , 1 ) == FAILURE ) {
4933
4922
err = 1 ;
4934
4923
} else {
4935
- ZVAL_STRING (& new_val , Z_STRVAL_P (val ));
4936
- php_pgsql_add_quotes (& new_val , 1 );
4924
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4937
4925
}
4938
4926
#undef REGEX0
4939
4927
}
@@ -4965,8 +4953,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4965
4953
err = 1 ;
4966
4954
}
4967
4955
else {
4968
- ZVAL_STR (& new_val , Z_STR_P (val ));
4969
- php_pgsql_add_quotes (& new_val , 1 );
4956
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4970
4957
}
4971
4958
#undef REGEX0
4972
4959
}
@@ -4998,8 +4985,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4998
4985
err = 1 ;
4999
4986
}
5000
4987
else {
5001
- ZVAL_STR (& new_val , Z_STR_P (val ));
5002
- php_pgsql_add_quotes (& new_val , 1 );
4988
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
5003
4989
}
5004
4990
#undef REGEX0
5005
4991
}
@@ -5077,8 +5063,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
5077
5063
err = 1 ;
5078
5064
}
5079
5065
else {
5080
- ZVAL_STRING (& new_val , Z_STRVAL_P (val ));
5081
- php_pgsql_add_quotes (& new_val , 1 );
5066
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
5082
5067
}
5083
5068
#undef REGEX0
5084
5069
}
@@ -5105,14 +5090,14 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
5105
5090
else {
5106
5091
unsigned char * tmp ;
5107
5092
size_t to_len ;
5093
+ zend_string * tmp_zstr ;
5108
5094
smart_str s = {0 };
5109
5095
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' */
5096
+ tmp_zstr = zend_string_init (( char * )tmp , to_len - 1 , false ); /* PQescapeBytea's to_len includes additional '\0' */
5111
5097
PQfreemem (tmp );
5112
- php_pgsql_add_quotes (& new_val , 1 );
5113
- smart_str_appendl (& s , Z_STRVAL (new_val ), Z_STRLEN (new_val ));
5098
+ smart_str_append (& s , php_pgsql_add_quotes (tmp_zstr ));
5114
5099
smart_str_0 (& s );
5115
- zval_ptr_dtor ( & new_val );
5100
+ zend_string_release ( tmp_zstr );
5116
5101
ZVAL_NEW_STR (& new_val , s .s );
5117
5102
}
5118
5103
break ;
@@ -5151,8 +5136,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
5151
5136
err = 1 ;
5152
5137
}
5153
5138
else {
5154
- ZVAL_STR (& new_val , Z_STR_P (val ));
5155
- php_pgsql_add_quotes (& new_val , 1 );
5139
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
5156
5140
}
5157
5141
#undef REGEX0
5158
5142
}
0 commit comments