Commit:    540f325664a6f4975cf005f367c95ece04757714
Author:    Matteo Beccati <mbecc...@php.net>         Wed, 21 Aug 2013 11:21:43 
+0200
Parents:   696852f2bd500c9a2f54d7956ff13e57c0cb3f83
Branches:  PHP-5.4 PHP-5.5 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=540f325664a6f4975cf005f367c95ece04757714

Log:
Fixed compiler warnings in ext/pgsql

Changed paths:
  M  ext/pgsql/pgsql.c


Diff:
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index 3189070..41e304f 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' */


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to