Skip to content

Commit 64cfc82

Browse files
committed
spprintf: introduce %p extensions to replace custom specifiers
1 parent 0b5d980 commit 64cfc82

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

Zend/zend_compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8583,8 +8583,8 @@ static void zend_compile_closure_binding(znode *closure, zend_op_array *op_array
85838583

85848584
value = zend_hash_add(op_array->static_variables, var_name, &EG(uninitialized_zval));
85858585
if (!value) {
8586-
zend_error_noreturn_unchecked(E_COMPILE_ERROR,
8587-
"Cannot use variable $%S twice", var_name);
8586+
zend_error_noreturn(E_COMPILE_ERROR,
8587+
"Cannot use variable $%pS twice", var_name);
85888588
}
85898589

85908590
CG(zend_lineno) = zend_ast_get_lineno(var_name_ast);

main/spprintf.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ static void xbuf_format_converter(void *xbuf, bool is_char, const char *fmt, va_
362362
break;
363363
}
364364
case 'S': {
365+
format_zend_string:;
365366
zend_string *str = va_arg(ap, zend_string*);
366367
s_len = ZSTR_LEN(str);
367368
s = ZSTR_VAL(str);
@@ -665,6 +666,13 @@ static void xbuf_format_converter(void *xbuf, bool is_char, const char *fmt, va_
665666
* we print "%p" to indicate that we don't handle "%p".
666667
*/
667668
case 'p':
669+
/* %p{Letter} extensions */
670+
switch (*(fmt+1)) {
671+
case 'S':
672+
fmt++;
673+
goto format_zend_string;
674+
}
675+
/* Normal %p */
668676
if (sizeof(char *) <= sizeof(uint64_t)) {
669677
ui_num = (uint64_t)((size_t) va_arg(ap, char *));
670678
s = ap_php_conv_p2(ui_num, 4, 'x',

0 commit comments

Comments
 (0)