Skip to content

Commit a1473aa

Browse files
committed
Avoid make_printable_zval in snprintf
Use zval_get_tmp_string() instead.
1 parent 5c5727a commit a1473aa

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

main/snprintf.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,6 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /
585585

586586
char *s = NULL;
587587
size_t s_len;
588-
int free_zcopy;
589-
zval *zvp, zcopy;
590588

591589
int min_width = 0;
592590
int precision = 0;
@@ -630,11 +628,11 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /
630628
/*
631629
* Default variable settings
632630
*/
631+
zend_string *tmp_str = NULL;
633632
adjust = RIGHT;
634633
alternate_form = print_sign = print_blank = NO;
635634
pad_char = ' ';
636635
prefix_char = NUL;
637-
free_zcopy = 0;
638636

639637
fmt++;
640638

@@ -768,13 +766,10 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /
768766
*/
769767
switch (*fmt) {
770768
case 'Z': {
771-
zvp = (zval*) va_arg(ap, zval*);
772-
free_zcopy = zend_make_printable_zval(zvp, &zcopy);
773-
if (free_zcopy) {
774-
zvp = &zcopy;
775-
}
776-
s_len = Z_STRLEN_P(zvp);
777-
s = Z_STRVAL_P(zvp);
769+
zval *zvp = va_arg(ap, zval*);
770+
zend_string *str = zval_get_tmp_string(zvp, &tmp_str);
771+
s_len = ZSTR_LEN(str);
772+
s = ZSTR_VAL(str);
778773
if (adjust_precision && (size_t)precision < s_len) {
779774
s_len = precision;
780775
}
@@ -1178,9 +1173,7 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /
11781173

11791174
if (adjust_width && adjust == LEFT && (size_t)min_width > s_len)
11801175
PAD(min_width, s_len, pad_char);
1181-
if (free_zcopy) {
1182-
zval_ptr_dtor_str(&zcopy);
1183-
}
1176+
zend_tmp_string_release(tmp_str);
11841177
}
11851178
skip_output:
11861179
fmt++;

0 commit comments

Comments
 (0)