summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatteo Beccati <mbeccati@php.net>2013-08-21 11:21:43 +0200
committerMatteo Beccati <mbeccati@php.net>2013-08-21 11:24:12 +0200
commit540f325664a6f4975cf005f367c95ece04757714 (patch)
tree72eb310f52e45f322a12343539670bfce00b024c
parent696852f2bd500c9a2f54d7956ff13e57c0cb3f83 (diff)
downloadphp-git-540f325664a6f4975cf005f367c95ece04757714.tar.gz
Fixed compiler warnings in ext/pgsql
-rw-r--r--ext/pgsql/pgsql.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index 3189070510..41e304fd31 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -4152,7 +4152,7 @@ PHP_FUNCTION(pg_escape_bytea)
#ifdef HAVE_PQESCAPE_BYTEA_CONN
if (pgsql_link != NULL || id != -1) {
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
- to = (char *)PQescapeByteaConn(pgsql, from, (size_t)from_len, &to_len);
+ to = (char *)PQescapeByteaConn(pgsql, (unsigned char *)from, (size_t)from_len, &to_len);
} else
#endif
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
#endif
static void php_pgsql_escape_internal(INTERNAL_FUNCTION_PARAMETERS, int escape_literal) {
- char *from = NULL, *to = NULL, *tmp = NULL;
+ char *from = NULL, *to = NULL;
zval *pgsql_link = NULL;
PGconn *pgsql;
int from_len;
@@ -4379,17 +4379,22 @@ static void php_pgsql_escape_internal(INTERNAL_FUNCTION_PARAMETERS, int escape_l
RETURN_FALSE;
}
#ifdef HAVE_PQESCAPELITERAL
- if (escape_literal) {
- tmp = PQescapeLiteral(pgsql, from, (size_t)from_len);
- } else {
- tmp = PQescapeIdentifier(pgsql, from, (size_t)from_len);
- }
- if (!tmp) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,"Failed to escape");
- RETURN_FALSE;
+ /* Use a block with a local var to avoid unused variable warnings */
+ {
+ char *tmp;
+
+ if (escape_literal) {
+ tmp = PQescapeLiteral(pgsql, from, (size_t)from_len);
+ } else {
+ tmp = PQescapeIdentifier(pgsql, from, (size_t)from_len);
+ }
+ if (!tmp) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,"Failed to escape");
+ RETURN_FALSE;
+ }
+ to = estrdup(tmp);
+ PQfreemem(tmp);
}
- to = estrdup(tmp);
- PQfreemem(tmp);
#else
to = php_pgsql_PQescapeInternal(pgsql, from, (size_t)from_len, escape_literal);
if (!to) {
@@ -5120,7 +5125,9 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z
#else
new_len = PQescapeString(escaped, tmp_name2, strlen(tmp_name2));
#endif
- smart_str_appends(&querystr, escaped);
+ if (new_len) {
+ smart_str_appends(&querystr, escaped);
+ }
efree(escaped);
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
#else
new_len = PQescapeString(escaped, tmp_name, strlen(tmp_name));
#endif
- smart_str_appends(&querystr, escaped);
+ if (new_len) {
+ smart_str_appends(&querystr, escaped);
+ }
efree(escaped);
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
size_t to_len;
smart_str s = {0};
#ifdef HAVE_PQESCAPE_BYTEA_CONN
- tmp = PQescapeByteaConn(pg_link, Z_STRVAL_PP(val), Z_STRLEN_PP(val), &to_len);
+ tmp = PQescapeByteaConn(pg_link, (unsigned char *)Z_STRVAL_PP(val), Z_STRLEN_PP(val), &to_len);
#else
- tmp = PQescapeBytea(Z_STRVAL_PP(val), Z_STRLEN_PP(val), &to_len);
+ tmp = PQescapeBytea(Z_STRVAL_PP(val), (unsigned char *)Z_STRLEN_PP(val), &to_len);
#endif
Z_TYPE_P(new_val) = IS_STRING;
Z_STRLEN_P(new_val) = to_len-1; /* PQescapeBytea's to_len includes additional '\0' */