summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYasuo Ohgaki <yohgaki@php.net>2014-02-16 07:51:50 +0900
committerYasuo Ohgaki <yohgaki@php.net>2014-02-16 07:51:50 +0900
commitf9537c2a0bf324a892182ff2dd3ec3218dba812a (patch)
treefdcc7183e855d628e752a52d26208776cd468004
parent8c9fd8fb534babc4b6fb0eee00dddb080cde83d7 (diff)
parent6f14b5ab4137e6505d595adf24615fc47ece67fd (diff)
downloadphp-git-f9537c2a0bf324a892182ff2dd3ec3218dba812a.tar.gz
Merge branch 'PHP-5.4' into PHP-5.5
* PHP-5.4: Refactor build_tablename()
-rw-r--r--ext/pgsql/pgsql.c35
1 files changed, 8 insertions, 27 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index 2a8c83201e..18960d1b37 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -1044,26 +1044,6 @@ static int _php_pgsql_detect_identifier_escape(const char *identifier, size_t le
}
-/* {{{ _php_pgsql_strndup, no strndup should be used */
-static char *_php_pgsql_strndup(const char *s, size_t len)
-{
- char *new;
-
- if (NULL == s) {
- return (char *)NULL;
- }
-
- new = (char *) malloc(len + 1);
-
- if (NULL == new) {
- return (char *)NULL;
- }
-
- new[len] = '\0';
-
- return memmove(new, s, len);
-}
-/* }}} */
/* {{{ PHP_INI
*/
@@ -6130,23 +6110,24 @@ static inline void build_tablename(smart_str *querystr, PGconn *pg_link, const c
token = php_strtok_r(table_copy, ".", &tmp);
len = strlen(token);
if (_php_pgsql_detect_identifier_escape(token, len) == SUCCESS) {
- escaped = _php_pgsql_strndup(token, len);
+ smart_str_appendl(querystr, token, len);
} else {
escaped = PGSQLescapeIdentifier(pg_link, token, len);
+ smart_str_appends(querystr, escaped);
+ PGSQLfree(escaped);
}
- smart_str_appends(querystr, escaped);
- PGSQLfree(escaped);
if (tmp && *tmp) {
len = strlen(tmp);
/* "schema"."table" format */
if (_php_pgsql_detect_identifier_escape(tmp, len) == SUCCESS) {
- escaped = _php_pgsql_strndup(tmp, len);
+ smart_str_appendc(querystr, '.');
+ smart_str_appendl(querystr, tmp, len);
} else {
escaped = PGSQLescapeIdentifier(pg_link, tmp, len);
+ smart_str_appendc(querystr, '.');
+ smart_str_appends(querystr, escaped);
+ PGSQLfree(escaped);
}
- smart_str_appendc(querystr, '.');
- smart_str_appends(querystr, escaped);
- PGSQLfree(escaped);
}
efree(table_copy);
}