Skip to content

Commit 540f325

Browse files
committed
Fixed compiler warnings in ext/pgsql
1 parent 696852f commit 540f325

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

ext/pgsql/pgsql.c

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4152,7 +4152,7 @@ PHP_FUNCTION(pg_escape_bytea)
41524152
#ifdef HAVE_PQESCAPE_BYTEA_CONN
41534153
if (pgsql_link != NULL || id != -1) {
41544154
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);
41564156
} else
41574157
#endif
41584158
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
43464346
#endif
43474347

43484348
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;
43504350
zval *pgsql_link = NULL;
43514351
PGconn *pgsql;
43524352
int from_len;
@@ -4379,17 +4379,22 @@ static void php_pgsql_escape_internal(INTERNAL_FUNCTION_PARAMETERS, int escape_l
43794379
RETURN_FALSE;
43804380
}
43814381
#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);
43904397
}
4391-
to = estrdup(tmp);
4392-
PQfreemem(tmp);
43934398
#else
43944399
to = php_pgsql_PQescapeInternal(pgsql, from, (size_t)from_len, escape_literal);
43954400
if (!to) {
@@ -5120,7 +5125,9 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z
51205125
#else
51215126
new_len = PQescapeString(escaped, tmp_name2, strlen(tmp_name2));
51225127
#endif
5123-
smart_str_appends(&querystr, escaped);
5128+
if (new_len) {
5129+
smart_str_appends(&querystr, escaped);
5130+
}
51245131
efree(escaped);
51255132

51265133
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
51305137
#else
51315138
new_len = PQescapeString(escaped, tmp_name, strlen(tmp_name));
51325139
#endif
5133-
smart_str_appends(&querystr, escaped);
5140+
if (new_len) {
5141+
smart_str_appends(&querystr, escaped);
5142+
}
51345143
efree(escaped);
51355144

51365145
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
59235932
size_t to_len;
59245933
smart_str s = {0};
59255934
#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);
59275936
#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);
59295938
#endif
59305939
Z_TYPE_P(new_val) = IS_STRING;
59315940
Z_STRLEN_P(new_val) = to_len-1; /* PQescapeBytea's to_len includes additional '\0' */

0 commit comments

Comments
 (0)