Skip to content

Commit 4283f75

Browse files
committed
Merge branch 'PHP-5.4' into PHP-5.5
* PHP-5.4: Fixed compiler warnings in ext/pgsql Fixed other compiler warnings in PDO_PGSQL Fixed compiler warning
2 parents 7be3c74 + 540f325 commit 4283f75

File tree

4 files changed

+34
-25
lines changed

4 files changed

+34
-25
lines changed

ext/pdo/php_pdo_driver.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ enum pdo_param_type {
7272
/* get_col ptr should point to a zval*
7373
and the driver is responsible for adding correct type information to get_column_meta()
7474
*/
75-
PDO_PARAM_ZVAL
76-
};
75+
PDO_PARAM_ZVAL,
7776

78-
/* magic flag to denote a parameter as being input/output */
79-
#define PDO_PARAM_INPUT_OUTPUT 0x80000000
77+
/* magic flag to denote a parameter as being input/output */
78+
PDO_PARAM_INPUT_OUTPUT = 0x80000000
79+
};
8080

8181
#define PDO_PARAM_FLAGS 0xFFFF0000
8282

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquote
315315
case PDO_PARAM_LOB:
316316
/* escapedlen returned by PQescapeBytea() accounts for trailing 0 */
317317
#ifdef HAVE_PQESCAPE_BYTEA_CONN
318-
escaped = PQescapeByteaConn(H->server, unquoted, unquotedlen, &tmp_len);
318+
escaped = PQescapeByteaConn(H->server, (unsigned char *)unquoted, (size_t)unquotedlen, &tmp_len);
319319
#else
320-
escaped = PQescapeBytea(unquoted, unquotedlen, &tmp_len);
320+
escaped = PQescapeBytea((unsigned char *)unquoted, (size_t)unquotedlen, &tmp_len);
321321
#endif
322322
*quotedlen = (int)tmp_len + 1;
323323
*quoted = emalloc(*quotedlen + 1);
@@ -331,9 +331,9 @@ static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquote
331331
*quoted = safe_emalloc(2, unquotedlen, 3);
332332
(*quoted)[0] = '\'';
333333
#ifndef HAVE_PQESCAPE_CONN
334-
*quotedlen = PQescapeString(*quoted + 1, unquoted, unquotedlen);
334+
*quotedlen = PQescapeString(*quoted + 1, unquoted, (size_t)unquotedlen);
335335
#else
336-
*quotedlen = PQescapeStringConn(H->server, *quoted + 1, unquoted, unquotedlen, NULL);
336+
*quotedlen = PQescapeStringConn(H->server, *quoted + 1, unquoted, (size_t)unquotedlen, NULL);
337337
#endif
338338
(*quoted)[*quotedlen + 1] = '\'';
339339
(*quoted)[*quotedlen + 2] = '\0';

ext/pdo_pgsql/pgsql_statement.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsigned
536536
*len = 0;
537537
return 0;
538538
} else {
539-
char *tmp_ptr = PQunescapeBytea(*ptr, &tmp_len);
539+
char *tmp_ptr = (char *)PQunescapeBytea((unsigned char *)*ptr, &tmp_len);
540540
if (!tmp_ptr) {
541541
/* PQunescapeBytea returned an error */
542542
*len = 0;

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);
@@ -4347,7 +4347,7 @@ static char* php_pgsql_PQescapeInternal(PGconn *conn, const char *str, size_t le
43474347
#endif
43484348

43494349
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;
43514351
zval *pgsql_link = NULL;
43524352
PGconn *pgsql;
43534353
int from_len;
@@ -4380,17 +4380,22 @@ static void php_pgsql_escape_internal(INTERNAL_FUNCTION_PARAMETERS, int escape_l
43804380
RETURN_FALSE;
43814381
}
43824382
#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);
43914398
}
4392-
to = estrdup(tmp);
4393-
PQfreemem(tmp);
43944399
#else
43954400
to = php_pgsql_PQescapeInternal(pgsql, from, (size_t)from_len, escape_literal);
43964401
if (!to) {
@@ -5121,7 +5126,9 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z
51215126
#else
51225127
new_len = PQescapeString(escaped, tmp_name2, strlen(tmp_name2));
51235128
#endif
5124-
smart_str_appends(&querystr, escaped);
5129+
if (new_len) {
5130+
smart_str_appends(&querystr, escaped);
5131+
}
51255132
efree(escaped);
51265133

51275134
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
51315138
#else
51325139
new_len = PQescapeString(escaped, tmp_name, strlen(tmp_name));
51335140
#endif
5134-
smart_str_appends(&querystr, escaped);
5141+
if (new_len) {
5142+
smart_str_appends(&querystr, escaped);
5143+
}
51355144
efree(escaped);
51365145

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

0 commit comments

Comments
 (0)