Skip to content

Commit 03e8115

Browse files
committed
Use zend_string_alloc directly
Hasn't been tested so this is a shot in the dark
1 parent 36aa38b commit 03e8115

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

ext/pdo_dblib/dblib_driver.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static zend_string* dblib_handle_quoter(pdo_dbh_t *dbh, const zend_string *unquo
147147
pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
148148
zend_bool use_national_character_set = 0;
149149
size_t i;
150-
char *q, *quoted;
150+
char *q;
151151
size_t quotedlen = 0;
152152
zend_string *quoted_str;
153153

@@ -171,7 +171,8 @@ static zend_string* dblib_handle_quoter(pdo_dbh_t *dbh, const zend_string *unquo
171171
if (use_national_character_set) {
172172
++quotedlen; /* N prefix */
173173
}
174-
q = quoted = emalloc(quotedlen + 1); /* Add byte for terminal null */
174+
quoted_str = zend_string_alloc(quotedlen, 0);
175+
q = ZSTR_VAL(quoted_str);
175176
if (use_national_character_set) {
176177
*q++ = 'N';
177178
}
@@ -185,16 +186,12 @@ static zend_string* dblib_handle_quoter(pdo_dbh_t *dbh, const zend_string *unquo
185186
*q++ = ZSTR_VAL(unquoted)[i];
186187
}
187188
}
188-
*q++ = '\'';
189-
190-
*q = 0;
189+
*q = '\'';
191190

192-
quoted_str = zend_string_init(quoted, quotedlen, 0);
193-
efree(quoted);
194191
return quoted_str;
195192
}
196193

197-
static bool pdo_dblib_transaction_cmd(const char *cmd, pdo_dbh_t *dbh)
194+
static bool pdo_dblib_transaction_cmd(const char *qmd, pdo_dbh_t *dbh)
198195
{
199196
pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
200197

ext/pdo_firebird/firebird_driver.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ static zend_string* firebird_handle_quoter(pdo_dbh_t *dbh, const zend_string *un
653653
{
654654
int qcount = 0;
655655
char const *co, *l, *r;
656-
char *c, *quoted;
656+
char *c;
657657
size_t quotedlen;
658658
zend_string *quoted_str;
659659

@@ -666,7 +666,8 @@ static zend_string* firebird_handle_quoter(pdo_dbh_t *dbh, const zend_string *un
666666
for (co = ZSTR_VAL(unquoted); (co = strchr(co,'\'')); qcount++, co++);
667667

668668
quotedlen = ZSTR_LEN(unquoted) + qcount + 2;
669-
quoted = c = emalloc(quotedlen+1);
669+
quoted_str = zend_string_alloc(quotedlen, 0);
670+
c = ZSTR_VAL(quoted_str);
670671
*c++ = '\'';
671672

672673
/* foreach (chunk that ends in a quote) */
@@ -678,12 +679,10 @@ static zend_string* firebird_handle_quoter(pdo_dbh_t *dbh, const zend_string *un
678679
}
679680

680681
/* copy the remainder */
681-
strncpy(c, l, quotedlen-(c-quoted)-1);
682-
quoted[quotedlen-1] = '\'';
683-
quoted[quotedlen] = '\0';
682+
strncpy(c, l, quotedlen-(c-ZSTR_VAL(quoted_str))-1);
683+
ZSTR_VAL(quoted_str)[quotedlen-1] = '\'';
684+
ZSTR_VAL(quoted_str)[quotedlen] = '\0';
684685

685-
quoted_str = zend_string_init(quoted, quotedlen, 0);
686-
efree(quoted);
687686
return quoted_str;
688687
}
689688
/* }}} */

0 commit comments

Comments
 (0)