Skip to content

Commit

Permalink
Avoid make_printable_zval in snprintf
Browse files Browse the repository at this point in the history
Use zval_get_tmp_string() instead.
  • Loading branch information
nikic committed Jun 10, 2021
1 parent 5c5727a commit a1473aa
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions main/snprintf.c
Expand Up @@ -585,8 +585,6 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /

char *s = NULL;
size_t s_len;
int free_zcopy;
zval *zvp, zcopy;

int min_width = 0;
int precision = 0;
Expand Down Expand Up @@ -630,11 +628,11 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /
/*
* Default variable settings
*/
zend_string *tmp_str = NULL;
adjust = RIGHT;
alternate_form = print_sign = print_blank = NO;
pad_char = ' ';
prefix_char = NUL;
free_zcopy = 0;

fmt++;

Expand Down Expand Up @@ -768,13 +766,10 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /
*/
switch (*fmt) {
case 'Z': {
zvp = (zval*) va_arg(ap, zval*);
free_zcopy = zend_make_printable_zval(zvp, &zcopy);
if (free_zcopy) {
zvp = &zcopy;
}
s_len = Z_STRLEN_P(zvp);
s = Z_STRVAL_P(zvp);
zval *zvp = va_arg(ap, zval*);
zend_string *str = zval_get_tmp_string(zvp, &tmp_str);
s_len = ZSTR_LEN(str);
s = ZSTR_VAL(str);
if (adjust_precision && (size_t)precision < s_len) {
s_len = precision;
}
Expand Down Expand Up @@ -1178,9 +1173,7 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /

if (adjust_width && adjust == LEFT && (size_t)min_width > s_len)
PAD(min_width, s_len, pad_char);
if (free_zcopy) {
zval_ptr_dtor_str(&zcopy);
}
zend_tmp_string_release(tmp_str);
}
skip_output:
fmt++;
Expand Down

0 comments on commit a1473aa

Please sign in to comment.