@@ -70,8 +70,7 @@ static int scan(Scanner *s)
70
70
struct placeholder {
71
71
const char *pos;
72
72
size_t len;
73
- size_t qlen; /* quoted length of value */
74
- char *quoted; /* quoted value */
73
+ zend_string *quoted; /* quoted value */
75
74
int freeq;
76
75
int bindno;
77
76
struct placeholder *next;
@@ -123,8 +122,7 @@ PDO_API int pdo_parse_params(pdo_stmt_t *stmt, zend_string *inquery, zend_string
123
122
124
123
if (t == PDO_PARSER_ESCAPED_QUESTION) {
125
124
plc->bindno = PDO_PARSER_BINDNO_ESCAPED_CHAR;
126
- plc->quoted = " ?" ;
127
- plc->qlen = 1 ;
125
+ plc->quoted = ZSTR_KNOWN (ZEND_STR_QUESTION_MARK);
128
126
plc->freeq = 0 ;
129
127
escapes++;
130
128
} else {
@@ -243,9 +241,8 @@ safe:
243
241
}
244
242
245
243
quoted_buf = stmt->dbh ->methods ->quoter (stmt->dbh , buf, param->param_type );
246
- plc->quoted = estrndup (ZSTR_VAL (quoted_buf), ZSTR_LEN (quoted_buf));
247
- plc->qlen = ZSTR_LEN (quoted_buf);
248
- zend_string_release_ex (quoted_buf, 0 );
244
+ plc->quoted = quoted_buf;
245
+ plc->freeq = 1 ;
249
246
250
247
if (buf) {
251
248
zend_string_release_ex (buf, 0 );
@@ -255,7 +252,6 @@ safe:
255
252
ret = -1 ;
256
253
goto clean_up;
257
254
}
258
- plc->freeq = 1 ;
259
255
} else {
260
256
enum pdo_param_type param_type = param->param_type ;
261
257
zend_string *buf = NULL ;
@@ -267,22 +263,17 @@ safe:
267
263
268
264
switch (param_type) {
269
265
case PDO_PARAM_BOOL:
270
- plc->quoted = zend_is_true (parameter) ? " 1" : " 0" ;
271
- plc->qlen = sizeof (" 1" )-1 ;
266
+ plc->quoted = zend_is_true (parameter) ? ZSTR_KNOWN (ZEND_STR_1) : ZSTR_KNOWN (ZEND_STR_0);
272
267
plc->freeq = 0 ;
273
268
break ;
274
269
275
270
case PDO_PARAM_INT:
276
- buf = zend_long_to_str (zval_get_long (parameter));
277
-
278
- plc->qlen = ZSTR_LEN (buf);
279
- plc->quoted = estrdup (ZSTR_VAL (buf));
271
+ plc->quoted = zend_long_to_str (zval_get_long (parameter));
280
272
plc->freeq = 1 ;
281
273
break ;
282
274
283
275
case PDO_PARAM_NULL:
284
- plc->quoted = " NULL" ;
285
- plc->qlen = sizeof (" NULL" )-1 ;
276
+ plc->quoted = ZSTR_KNOWN (ZEND_STR_NULL);
286
277
plc->freeq = 0 ;
287
278
break ;
288
279
@@ -304,10 +295,8 @@ safe:
304
295
}
305
296
306
297
quoted_buf = stmt->dbh ->methods ->quoter (stmt->dbh , buf, param_type);
307
- plc->quoted = estrndup (ZSTR_VAL (quoted_buf), ZSTR_LEN (quoted_buf));
308
- plc->qlen = ZSTR_LEN (quoted_buf);
298
+ plc->quoted = quoted_buf;
309
299
plc->freeq = 1 ;
310
- zend_string_release_ex (quoted_buf, 0 );
311
300
}
312
301
}
313
302
@@ -322,10 +311,9 @@ safe:
322
311
} else {
323
312
parameter = ¶m->parameter ;
324
313
}
325
- plc->quoted = Z_STRVAL_P (parameter);
326
- plc->qlen = Z_STRLEN_P (parameter);
314
+ plc->quoted = Z_STR_P (parameter);
327
315
}
328
- newbuffer_len += plc->qlen ;
316
+ newbuffer_len += ZSTR_LEN ( plc->quoted ) ;
329
317
}
330
318
331
319
rewrite:
@@ -344,8 +332,8 @@ rewrite:
344
332
newbuffer += t;
345
333
}
346
334
if (plc->quoted ) {
347
- memcpy (newbuffer, plc->quoted , plc->qlen );
348
- newbuffer += plc->qlen ;
335
+ memcpy (newbuffer, ZSTR_VAL ( plc->quoted ), ZSTR_LEN ( plc->quoted ) );
336
+ newbuffer += ZSTR_LEN ( plc->quoted ) ;
349
337
} else {
350
338
memcpy (newbuffer, plc->pos , plc->len );
351
339
newbuffer += plc->len ;
@@ -368,7 +356,7 @@ rewrite:
368
356
369
357
} else if (query_type == PDO_PLACEHOLDER_POSITIONAL) {
370
358
/* rewrite ? to :pdoX */
371
- char *name, *idxbuf ;
359
+ char *name;
372
360
const char *tmpl = stmt->named_rewrite_template ? stmt->named_rewrite_template : " :pdo%d" ;
373
361
int bind_no = 1 ;
374
362
@@ -382,6 +370,7 @@ rewrite:
382
370
for (plc = placeholders; plc; plc = plc->next ) {
383
371
int skip_map = 0 ;
384
372
char *p;
373
+ zend_string *idxbuf;
385
374
386
375
if (plc->bindno == PDO_PARSER_BINDNO_ESCAPED_CHAR) {
387
376
continue ;
@@ -391,24 +380,23 @@ rewrite:
391
380
392
381
/* check if bound parameter is already available */
393
382
if (!strcmp (name, " ?" ) || (p = zend_hash_str_find_ptr (stmt->bound_param_map , name, plc->len )) == NULL ) {
394
- spprintf (& idxbuf, 0 , tmpl, bind_no++);
383
+ idxbuf = strpprintf ( 0 , tmpl, bind_no++);
395
384
} else {
396
- idxbuf = estrdup (p );
385
+ idxbuf = zend_string_init (p, strlen (p), 0 );
397
386
skip_map = 1 ;
398
387
}
399
388
400
389
plc->quoted = idxbuf;
401
- plc->qlen = strlen (plc->quoted );
402
390
plc->freeq = 1 ;
403
- newbuffer_len += plc->qlen ;
391
+ newbuffer_len += ZSTR_LEN ( plc->quoted ) ;
404
392
405
393
if (!skip_map && stmt->named_rewrite_template ) {
406
394
/* create a mapping */
407
- zend_hash_str_update_mem (stmt->bound_param_map , name, plc->len , idxbuf, plc->qlen + 1 );
395
+ zend_hash_str_update_mem (stmt->bound_param_map , name, plc->len , ZSTR_VAL (plc-> quoted ), ZSTR_LEN ( plc->quoted ) + 1 );
408
396
}
409
397
410
398
/* map number to name */
411
- zend_hash_index_update_mem (stmt->bound_param_map , plc->bindno , idxbuf, plc->qlen + 1 );
399
+ zend_hash_index_update_mem (stmt->bound_param_map , plc->bindno , ZSTR_VAL (plc-> quoted ), ZSTR_LEN ( plc->quoted ) + 1 );
412
400
413
401
efree (name);
414
402
}
@@ -430,8 +418,7 @@ rewrite:
430
418
name = estrndup (plc->pos , plc->len );
431
419
zend_hash_index_update_mem (stmt->bound_param_map , plc->bindno , name, plc->len + 1 );
432
420
efree (name);
433
- plc->quoted = " ?" ;
434
- plc->qlen = 1 ;
421
+ plc->quoted = ZSTR_KNOWN (ZEND_STR_QUESTION_MARK);
435
422
newbuffer_len -= plc->len - 1 ;
436
423
}
437
424
@@ -445,7 +432,7 @@ clean_up:
445
432
placeholders = plc->next ;
446
433
447
434
if (plc->freeq ) {
448
- efree (plc->quoted );
435
+ zend_string_release_ex (plc->quoted , 0 );
449
436
}
450
437
451
438
efree (plc);
0 commit comments