Skip to content

Commit dd91170

Browse files
committed
Avoid make_printable_zval() in other printf implementations as well
This is the same as the previous commit, for copies of that code.
1 parent a1473aa commit dd91170

File tree

2 files changed

+14
-27
lines changed

2 files changed

+14
-27
lines changed

main/spprintf.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ static void xbuf_format_converter(void *xbuf, bool is_char, const char *fmt, va_
189189
{
190190
char *s = NULL;
191191
size_t s_len;
192-
int free_zcopy;
193-
zval *zvp, zcopy;
194192

195193
int min_width = 0;
196194
int precision = 0;
@@ -231,11 +229,11 @@ static void xbuf_format_converter(void *xbuf, bool is_char, const char *fmt, va_
231229
/*
232230
* Default variable settings
233231
*/
232+
zend_string *tmp_str = NULL;
234233
adjust = RIGHT;
235234
alternate_form = print_sign = print_blank = NO;
236235
pad_char = ' ';
237236
prefix_char = NUL;
238-
free_zcopy = 0;
239237

240238
fmt++;
241239

@@ -375,13 +373,10 @@ static void xbuf_format_converter(void *xbuf, bool is_char, const char *fmt, va_
375373
*/
376374
switch (*fmt) {
377375
case 'Z': {
378-
zvp = (zval*) va_arg(ap, zval*);
379-
free_zcopy = zend_make_printable_zval(zvp, &zcopy);
380-
if (free_zcopy) {
381-
zvp = &zcopy;
382-
}
383-
s_len = Z_STRLEN_P(zvp);
384-
s = Z_STRVAL_P(zvp);
376+
zval *zvp = va_arg(ap, zval*);
377+
zend_string *str = zval_get_tmp_string(zvp, &tmp_str);
378+
s_len = ZSTR_LEN(str);
379+
s = ZSTR_VAL(str);
385380
if (adjust_precision && (size_t)precision < s_len) {
386381
s_len = precision;
387382
}
@@ -783,9 +778,7 @@ static void xbuf_format_converter(void *xbuf, bool is_char, const char *fmt, va_
783778
PAD_CHAR(xbuf, pad_char, min_width - s_len, is_char);
784779
}
785780

786-
if (free_zcopy) {
787-
zval_ptr_dtor_str(&zcopy);
788-
}
781+
zend_tmp_string_release(tmp_str);
789782
}
790783
skip_output:
791784
fmt++;

sapi/phpdbg/phpdbg_out.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ static int format_converter(register buffy *odp, const char *fmt, bool escape_xm
130130

131131
char *s = NULL, *free_s = NULL;
132132
size_t s_len;
133-
bool free_zcopy;
134-
zval *zvp, zcopy;
135133

136134
int min_width = 0;
137135
int precision = 0;
@@ -171,11 +169,11 @@ static int format_converter(register buffy *odp, const char *fmt, bool escape_xm
171169
/*
172170
* Default variable settings
173171
*/
172+
zend_string *tmp_str = NULL;
174173
adjust = RIGHT;
175174
alternate_form = print_sign = print_blank = NO;
176175
pad_char = ' ';
177176
prefix_char = NUL;
178-
free_zcopy = 0;
179177

180178
fmt++;
181179

@@ -323,18 +321,16 @@ static int format_converter(register buffy *odp, const char *fmt, bool escape_xm
323321
* It is reset to ' ' by non-numeric formats
324322
*/
325323
switch (*fmt) {
326-
case 'Z':
327-
zvp = (zval *) va_arg(ap, zval *);
328-
free_zcopy = zend_make_printable_zval(zvp, &zcopy);
329-
if (free_zcopy) {
330-
zvp = &zcopy;
331-
}
332-
s_len = Z_STRLEN_P(zvp);
333-
s = Z_STRVAL_P(zvp);
324+
case 'Z': {
325+
zval *zvp = va_arg(ap, zval *);
326+
zend_string *str = zval_get_tmp_string(zvp, &tmp_str);
327+
s_len = ZSTR_LEN(str);
328+
s = ZSTR_VAL(str);
334329
if (adjust_precision && precision < s_len) {
335330
s_len = precision;
336331
}
337332
break;
333+
}
338334
case 'u':
339335
switch(modifier) {
340336
default:
@@ -790,9 +786,7 @@ static int format_converter(register buffy *odp, const char *fmt, bool escape_xm
790786

791787
if (adjust_width && adjust == LEFT && min_width > s_len)
792788
PAD(min_width, s_len, pad_char);
793-
if (free_zcopy) {
794-
zval_ptr_dtor_str(&zcopy);
795-
}
789+
zend_tmp_string_release(tmp_str);
796790
}
797791
skip_output:
798792
if (free_s) {

0 commit comments

Comments
 (0)