@@ -4510,24 +4510,9 @@ 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
- smart_str str = {0 };
4516
-
4517
- ZEND_ASSERT (Z_TYPE_P (src ) == IS_STRING );
4518
-
4519
- smart_str_appendc (& str , 'E' );
4520
- smart_str_appendc (& str , '\'' );
4521
- smart_str_appendl (& str , Z_STRVAL_P (src ), Z_STRLEN_P (src ));
4522
- smart_str_appendc (& str , '\'' );
4523
- smart_str_0 (& str );
4524
-
4525
- if (should_free ) {
4526
- zval_ptr_dtor (src );
4527
- }
4528
- ZVAL_NEW_STR (src , str .s );
4529
-
4530
- return SUCCESS ;
4515
+ return zend_string_concat3 ("E'" , strlen ("E'" ), ZSTR_VAL (src ), ZSTR_LEN (src ), "'" , strlen ("'" ));
4531
4516
}
4532
4517
/* }}} */
4533
4518
@@ -4740,8 +4725,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
4740
4725
if (php_pgsql_convert_match (Z_STR_P (val ), REGEX1 , sizeof (REGEX1 )- 1 , 1 ) == FAILURE ) {
4741
4726
err = 1 ;
4742
4727
} else {
4743
- ZVAL_STRING (& new_val , Z_STRVAL_P (val ));
4744
- php_pgsql_add_quotes (& new_val , 1 );
4728
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4745
4729
}
4746
4730
}
4747
4731
else {
@@ -4808,8 +4792,8 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
4808
4792
/* better to use PGSQLescapeLiteral since PGescapeStringConn does not handle special \ */
4809
4793
ZSTR_LEN (str ) = PQescapeStringConn (pg_link , ZSTR_VAL (str ), Z_STRVAL_P (val ), Z_STRLEN_P (val ), NULL );
4810
4794
str = zend_string_truncate (str , ZSTR_LEN (str ), 0 );
4811
- ZVAL_NEW_STR (& new_val , str );
4812
- php_pgsql_add_quotes ( & new_val , 1 );
4795
+ ZVAL_STR (& new_val , php_pgsql_add_quotes ( str ) );
4796
+ zend_string_release_ex ( str , false );
4813
4797
}
4814
4798
break ;
4815
4799
@@ -4895,8 +4879,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
4895
4879
err = 1 ;
4896
4880
}
4897
4881
else {
4898
- ZVAL_STRINGL (& new_val , Z_STRVAL_P (val ), Z_STRLEN_P (val ));
4899
- php_pgsql_add_quotes (& new_val , 1 );
4882
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4900
4883
}
4901
4884
#undef REGEX0
4902
4885
#undef REGEX1
@@ -4931,8 +4914,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
4931
4914
if (php_pgsql_convert_match (Z_STR_P (val ), REGEX0 , sizeof (REGEX0 )- 1 , 1 ) == FAILURE ) {
4932
4915
err = 1 ;
4933
4916
} else {
4934
- ZVAL_STRING (& new_val , Z_STRVAL_P (val ));
4935
- php_pgsql_add_quotes (& new_val , 1 );
4917
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4936
4918
}
4937
4919
#undef REGEX0
4938
4920
}
@@ -4964,8 +4946,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
4964
4946
err = 1 ;
4965
4947
}
4966
4948
else {
4967
- ZVAL_STRINGL (& new_val , Z_STRVAL_P (val ), Z_STRLEN_P (val ));
4968
- php_pgsql_add_quotes (& new_val , 1 );
4949
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4969
4950
}
4970
4951
#undef REGEX0
4971
4952
}
@@ -4997,8 +4978,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
4997
4978
err = 1 ;
4998
4979
}
4999
4980
else {
5000
- ZVAL_STRINGL (& new_val , Z_STRVAL_P (val ), Z_STRLEN_P (val ));
5001
- php_pgsql_add_quotes (& new_val , 1 );
4981
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
5002
4982
}
5003
4983
#undef REGEX0
5004
4984
}
@@ -5076,8 +5056,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
5076
5056
err = 1 ;
5077
5057
}
5078
5058
else {
5079
- ZVAL_STRING (& new_val , Z_STRVAL_P (val ));
5080
- php_pgsql_add_quotes (& new_val , 1 );
5059
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
5081
5060
}
5082
5061
#undef REGEX0
5083
5062
}
@@ -5104,15 +5083,14 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
5104
5083
else {
5105
5084
unsigned char * tmp ;
5106
5085
size_t to_len ;
5107
- smart_str s = {0 };
5086
+ zend_string * tmp_zstr ;
5087
+
5108
5088
tmp = PQescapeByteaConn (pg_link , (unsigned char * )Z_STRVAL_P (val ), Z_STRLEN_P (val ), & to_len );
5109
- ZVAL_STRINGL ( & new_val , ( char * )tmp , to_len - 1 ); /* PQescapeBytea's to_len includes additional '\0' */
5089
+ tmp_zstr = zend_string_init (( char * )tmp , to_len - 1 , false ); /* PQescapeBytea's to_len includes additional '\0' */
5110
5090
PQfreemem (tmp );
5111
- php_pgsql_add_quotes (& new_val , 1 );
5112
- smart_str_appendl (& s , Z_STRVAL (new_val ), Z_STRLEN (new_val ));
5113
- smart_str_0 (& s );
5114
- zval_ptr_dtor (& new_val );
5115
- ZVAL_NEW_STR (& new_val , s .s );
5091
+
5092
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (tmp_zstr ));
5093
+ zend_string_release_ex (tmp_zstr , false);
5116
5094
}
5117
5095
break ;
5118
5096
@@ -5150,8 +5128,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
5150
5128
err = 1 ;
5151
5129
}
5152
5130
else {
5153
- ZVAL_STRINGL (& new_val , Z_STRVAL_P (val ), Z_STRLEN_P (val ));
5154
- php_pgsql_add_quotes (& new_val , 1 );
5131
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
5155
5132
}
5156
5133
#undef REGEX0
5157
5134
}
0 commit comments