summaryrefslogtreecommitdiff
path: root/ext/pdo_firebird/firebird_driver.c
diff options
context:
space:
mode:
authorGeorge Peter Banyard <girgias@php.net>2020-12-23 15:58:10 +0100
committerGeorge Peter Banyard <girgias@php.net>2021-01-07 15:53:48 +0000
commit63cda0fea83d19d17d19df18d712328372e7891c (patch)
tree805c6ddfeeb5fd2de0920bf976e091702e41e9cf /ext/pdo_firebird/firebird_driver.c
parentdf0fa5b1787c6b26b6abfb721d7b5a00b77a1fb6 (diff)
downloadphp-git-63cda0fea83d19d17d19df18d712328372e7891c.tar.gz
Refactor PDO's quoter handler to return a zend_string
Closes GH-6547
Diffstat (limited to 'ext/pdo_firebird/firebird_driver.c')
-rw-r--r--ext/pdo_firebird/firebird_driver.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/ext/pdo_firebird/firebird_driver.c b/ext/pdo_firebird/firebird_driver.c
index d51ca61eff..858cf53035 100644
--- a/ext/pdo_firebird/firebird_driver.c
+++ b/ext/pdo_firebird/firebird_driver.c
@@ -649,30 +649,29 @@ free_statement:
/* }}} */
/* called by the PDO SQL parser to add quotes to values that are copied into SQL */
-static bool firebird_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, /* {{{ */
- char **quoted, size_t *quotedlen, enum pdo_param_type paramtype)
+static zend_string* firebird_handle_quoter(pdo_dbh_t *dbh, const zend_string *unquoted, enum pdo_param_type paramtype)
{
int qcount = 0;
char const *co, *l, *r;
char *c;
+ size_t quotedlen;
+ zend_string *quoted_str;
- if (!unquotedlen) {
- *quotedlen = 2;
- *quoted = emalloc(*quotedlen+1);
- strcpy(*quoted, "''");
- return true;
+ if (ZSTR_LEN(unquoted) == 0) {
+ return zend_string_init("''", 2, 0);
}
/* Firebird only requires single quotes to be doubled if string lengths are used */
/* count the number of ' characters */
- for (co = unquoted; (co = strchr(co,'\'')); qcount++, co++);
+ for (co = ZSTR_VAL(unquoted); (co = strchr(co,'\'')); qcount++, co++);
- *quotedlen = unquotedlen + qcount + 2;
- *quoted = c = emalloc(*quotedlen+1);
+ quotedlen = ZSTR_LEN(unquoted) + qcount + 2;
+ quoted_str = zend_string_alloc(quotedlen, 0);
+ c = ZSTR_VAL(quoted_str);
*c++ = '\'';
/* foreach (chunk that ends in a quote) */
- for (l = unquoted; (r = strchr(l,'\'')); l = r+1) {
+ for (l = ZSTR_VAL(unquoted); (r = strchr(l,'\'')); l = r+1) {
strncpy(c, l, r-l+1);
c += (r-l+1);
/* add the second quote */
@@ -680,11 +679,11 @@ static bool firebird_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t
}
/* copy the remainder */
- strncpy(c, l, *quotedlen-(c-*quoted)-1);
- (*quoted)[*quotedlen-1] = '\'';
- (*quoted)[*quotedlen] = '\0';
+ strncpy(c, l, quotedlen-(c-ZSTR_VAL(quoted_str))-1);
+ ZSTR_VAL(quoted_str)[quotedlen-1] = '\'';
+ ZSTR_VAL(quoted_str)[quotedlen] = '\0';
- return true;
+ return quoted_str;
}
/* }}} */