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