Skip to content

Commit af0fd86

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

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

ext/pdo_dblib/dblib_driver.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ 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;
151150
size_t quotedlen = 0;
152151
zend_string *quoted_str;
153152

@@ -171,26 +170,21 @@ static zend_string* dblib_handle_quoter(pdo_dbh_t *dbh, const zend_string *unquo
171170
if (use_national_character_set) {
172171
++quotedlen; /* N prefix */
173172
}
174-
q = quoted = emalloc(quotedlen + 1); /* Add byte for terminal null */
173+
quoted_str = zend_string_alloc(quotedlen, 0);
175174
if (use_national_character_set) {
176-
*q++ = 'N';
175+
*ZSTR_VAL(quoted_str)++ = 'N';
177176
}
178-
*q++ = '\'';
177+
*ZSTR_VAL(quoted_str)++ = '\'';
179178

180179
for (i = 0; i < ZSTR_LEN(unquoted); i++) {
181180
if (ZSTR_VAL(unquoted)[i] == '\'') {
182-
*q++ = '\'';
183-
*q++ = '\'';
181+
*ZSTR_VAL(quoted_str)++ = '\'';
182+
*ZSTR_VAL(quoted_str)++ = '\'';
184183
} else {
185-
*q++ = ZSTR_VAL(unquoted)[i];
184+
*ZSTR_VAL(quoted_str)++ = ZSTR_VAL(unquoted)[i];
186185
}
187186
}
188-
*q++ = '\'';
189-
190-
*q = 0;
191-
192-
quoted_str = zend_string_init(quoted, quotedlen, 0);
193-
efree(quoted);
187+
*ZSTR_VAL(quoted_str) = '\'';
194188
return quoted_str;
195189
}
196190

ext/pdo_firebird/firebird_driver.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,6 @@ 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;
657656
size_t quotedlen;
658657
zend_string *quoted_str;
659658

@@ -666,24 +665,22 @@ static zend_string* firebird_handle_quoter(pdo_dbh_t *dbh, const zend_string *un
666665
for (co = ZSTR_VAL(unquoted); (co = strchr(co,'\'')); qcount++, co++);
667666

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

672671
/* foreach (chunk that ends in a quote) */
673672
for (l = ZSTR_VAL(unquoted); (r = strchr(l,'\'')); l = r+1) {
674-
strncpy(c, l, r-l+1);
675-
c += (r-l+1);
673+
strncpy(ZSTR_VAL(quoted_str), l, r-l+1);
674+
ZSTR_VAL(quoted_str) += (r-l+1);
676675
/* add the second quote */
677-
*c++ = '\'';
676+
*ZSTR_VAL(quoted_str)++ = '\'';
678677
}
679678

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

685-
quoted_str = zend_string_init(quoted, quotedlen, 0);
686-
efree(quoted);
687684
return quoted_str;
688685
}
689686
/* }}} */

0 commit comments

Comments
 (0)