@@ -4152,7 +4152,7 @@ PHP_FUNCTION(pg_escape_bytea)
4152
4152
#ifdef HAVE_PQESCAPE_BYTEA_CONN
4153
4153
if (pgsql_link != NULL || id != -1 ) {
4154
4154
ZEND_FETCH_RESOURCE2 (pgsql , PGconn * , & pgsql_link , id , "PostgreSQL link" , le_link , le_plink );
4155
- to = (char * )PQescapeByteaConn (pgsql , from , (size_t )from_len , & to_len );
4155
+ to = (char * )PQescapeByteaConn (pgsql , ( unsigned char * ) from , (size_t )from_len , & to_len );
4156
4156
} else
4157
4157
#endif
4158
4158
to = (char * )PQescapeBytea ((unsigned char * )from , from_len , & to_len );
@@ -4347,7 +4347,7 @@ static char* php_pgsql_PQescapeInternal(PGconn *conn, const char *str, size_t le
4347
4347
#endif
4348
4348
4349
4349
static void php_pgsql_escape_internal (INTERNAL_FUNCTION_PARAMETERS , int escape_literal ) {
4350
- char * from = NULL , * to = NULL , * tmp = NULL ;
4350
+ char * from = NULL , * to = NULL ;
4351
4351
zval * pgsql_link = NULL ;
4352
4352
PGconn * pgsql ;
4353
4353
int from_len ;
@@ -4380,17 +4380,22 @@ static void php_pgsql_escape_internal(INTERNAL_FUNCTION_PARAMETERS, int escape_l
4380
4380
RETURN_FALSE ;
4381
4381
}
4382
4382
#ifdef HAVE_PQESCAPELITERAL
4383
- if (escape_literal ) {
4384
- tmp = PQescapeLiteral (pgsql , from , (size_t )from_len );
4385
- } else {
4386
- tmp = PQescapeIdentifier (pgsql , from , (size_t )from_len );
4387
- }
4388
- if (!tmp ) {
4389
- php_error_docref (NULL TSRMLS_CC , E_WARNING ,"Failed to escape ");
4390
- RETURN_FALSE ;
4383
+ /* Use a block with a local var to avoid unused variable warnings */
4384
+ {
4385
+ char * tmp ;
4386
+
4387
+ if (escape_literal ) {
4388
+ tmp = PQescapeLiteral (pgsql , from , (size_t )from_len );
4389
+ } else {
4390
+ tmp = PQescapeIdentifier (pgsql , from , (size_t )from_len );
4391
+ }
4392
+ if (!tmp ) {
4393
+ php_error_docref (NULL TSRMLS_CC , E_WARNING ,"Failed to escape ");
4394
+ RETURN_FALSE ;
4395
+ }
4396
+ to = estrdup (tmp );
4397
+ PQfreemem (tmp );
4391
4398
}
4392
- to = estrdup (tmp );
4393
- PQfreemem (tmp );
4394
4399
#else
4395
4400
to = php_pgsql_PQescapeInternal (pgsql , from , (size_t )from_len , escape_literal );
4396
4401
if (!to ) {
@@ -5121,7 +5126,9 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z
5121
5126
#else
5122
5127
new_len = PQescapeString (escaped , tmp_name2 , strlen (tmp_name2 ));
5123
5128
#endif
5124
- smart_str_appends (& querystr , escaped );
5129
+ if (new_len ) {
5130
+ smart_str_appends (& querystr , escaped );
5131
+ }
5125
5132
efree (escaped );
5126
5133
5127
5134
smart_str_appends (& querystr , "' AND c.relnamespace = n.oid AND n.nspname = '" );
@@ -5131,7 +5138,9 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z
5131
5138
#else
5132
5139
new_len = PQescapeString (escaped , tmp_name , strlen (tmp_name ));
5133
5140
#endif
5134
- smart_str_appends (& querystr , escaped );
5141
+ if (new_len ) {
5142
+ smart_str_appends (& querystr , escaped );
5143
+ }
5135
5144
efree (escaped );
5136
5145
5137
5146
smart_str_appends (& querystr , "' AND a.atttypid = t.oid ORDER BY a.attnum;" );
@@ -5924,9 +5933,9 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
5924
5933
size_t to_len ;
5925
5934
smart_str s = {0 };
5926
5935
#ifdef HAVE_PQESCAPE_BYTEA_CONN
5927
- tmp = PQescapeByteaConn (pg_link , Z_STRVAL_PP (val ), Z_STRLEN_PP (val ), & to_len );
5936
+ tmp = PQescapeByteaConn (pg_link , ( unsigned char * ) Z_STRVAL_PP (val ), Z_STRLEN_PP (val ), & to_len );
5928
5937
#else
5929
- tmp = PQescapeBytea (Z_STRVAL_PP (val ), Z_STRLEN_PP (val ), & to_len );
5938
+ tmp = PQescapeBytea (Z_STRVAL_PP (val ), ( unsigned char * ) Z_STRLEN_PP (val ), & to_len );
5930
5939
#endif
5931
5940
Z_TYPE_P (new_val ) = IS_STRING ;
5932
5941
Z_STRLEN_P (new_val ) = to_len - 1 ; /* PQescapeBytea's to_len includes additional '\0' */
0 commit comments