diff --git a/NEWS b/NEWS index b3ac9d6b405bf..8f129d715d873 100644 --- a/NEWS +++ b/NEWS @@ -263,6 +263,8 @@ PHP NEWS (nielsdos) . Fixed exit code handling of sendmail cmd and added warnings. (Jesse Hathaway) + . Fixed bug GH-18897 (printf: empty precision is interpreted as precision 6, + not as precision 0). (nielsdos) - Streams: . Fixed bug GH-16889 (stream_select() timeout useless for pipes on Windows). diff --git a/UPGRADING b/UPGRADING index 1462be95a43fc..4dca8f2b2c213 100644 --- a/UPGRADING +++ b/UPGRADING @@ -116,6 +116,11 @@ PHP 8.5 UPGRADE NOTES . SplFileObject::fwrite's parameter $length is now nullable. The default value changed from 0 to null. +- Standard: + . Using a printf-family function with a formatter that did not specify the + precision previously incorrectly reset the precision instead of treating + it as a precision of 0. See GH-18897. + ======================================== 2. New Features ======================================== diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS index f421242dba6c6..acc9612b72e30 100644 --- a/UPGRADING.INTERNALS +++ b/UPGRADING.INTERNALS @@ -43,6 +43,8 @@ PHP 8.5 INTERNALS UPGRADE NOTES . Added the zend_update_exception_properties() function for instantiating Exception child classes. It updates the $message, $code, and $previous properties. + . ZEND_IS_XDIGIT() macro was removed because it was unused and its name + did not match its actual behavior. ======================== 2. Build system changes diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h index db86345b69968..a7537d1b3ef33 100644 --- a/Zend/zend_operators.h +++ b/Zend/zend_operators.h @@ -156,7 +156,6 @@ static zend_always_inline zend_long zend_dval_to_lval_safe(double d) } #define ZEND_IS_DIGIT(c) ((c) >= '0' && (c) <= '9') -#define ZEND_IS_XDIGIT(c) (((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f')) static zend_always_inline uint8_t is_numeric_string_ex(const char *str, size_t length, zend_long *lval, double *dval, bool allow_errors, int *oflow_info, bool *trailing_data) diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c index 9a74ae6c877f3..b2c287c02900c 100644 --- a/ext/standard/formatted_print.c +++ b/ext/standard/formatted_print.c @@ -591,6 +591,7 @@ php_formatted_print(char *format, size_t format_len, zval *args, int argc, int n expprec = 1; } else { precision = 0; + adjusting |= ADJ_PRECISION; } } else { precision = 0; diff --git a/ext/standard/tests/strings/gh18897.phpt b/ext/standard/tests/strings/gh18897.phpt new file mode 100644 index 0000000000000..328ea7161e023 --- /dev/null +++ b/ext/standard/tests/strings/gh18897.phpt @@ -0,0 +1,10 @@ +--TEST-- +GH-18897 (printf: empty precision is interpreted as precision 6, not as precision 0) +--FILE-- + +--EXPECT-- +3 +3 diff --git a/main/debug_gdb_scripts.c b/main/debug_gdb_scripts.c index 3806f6aab60dd..e3c522bc04843 100644 --- a/main/debug_gdb_scripts.c +++ b/main/debug_gdb_scripts.c @@ -719,6 +719,8 @@ asm( ".ascii \" for field in self.val.type.fields():\\n\"\n" ".ascii \" if field.name == 'val':\\n\"\n" ".ascii \" yield ('val', format_zstr(self.val))\\n\"\n" + ".ascii \" elif field.name == 'h':\\n\"\n" + ".ascii \" yield (field.name, \\\"0x%x\\\" % self.val[field.name])\\n\"\n" ".ascii \" else:\\n\"\n" ".ascii \" yield (field.name, format_nested(self.val[field.name]))\\n\"\n" ".ascii \"\\n\"\n" @@ -751,12 +753,11 @@ asm( ".ascii \" def children(self):\\n\"\n" ".ascii \" for field in self.val.type.fields():\\n\"\n" ".ascii \" if field.name is None:\\n\"\n" - ".ascii \" name = ''\\n\"\n" - ".ascii \" val = self.val[field]\\n\"\n" + ".ascii \" yield ('', format_nested(self.val[field]))\\n\"\n" + ".ascii \" elif field.name == 'nTableMask':\\n\"\n" + ".ascii \" yield (field.name, \\\"0x%x\\\" % self.val[field.name])\\n\"\n" ".ascii \" else:\\n\"\n" - ".ascii \" name = field.name\\n\"\n" - ".ascii \" val = self.val[field.name]\\n\"\n" - ".ascii \" yield (name, format_nested(val))\\n\"\n" + ".ascii \" yield (field.name, format_nested(self.val[field.name]))\\n\"\n" ".ascii \"\\n\"\n" ".ascii \"pp_set.add_printer('zend_array', '^_zend_array$', ZendArrayPrettyPrinter)\\n\"\n" ".ascii \"\\n\"\n" diff --git a/scripts/gdb/php_gdb.py b/scripts/gdb/php_gdb.py index ae8396a2ac0c2..1c5da0154aecd 100644 --- a/scripts/gdb/php_gdb.py +++ b/scripts/gdb/php_gdb.py @@ -49,6 +49,8 @@ def children(self): for field in self.val.type.fields(): if field.name == 'val': yield ('val', format_zstr(self.val)) + elif field.name == 'h': + yield (field.name, "0x%x" % self.val[field.name]) else: yield (field.name, format_nested(self.val[field.name])) @@ -81,12 +83,11 @@ def to_string(self): def children(self): for field in self.val.type.fields(): if field.name is None: - name = '' - val = self.val[field] + yield ('', format_nested(self.val[field])) + elif field.name == 'nTableMask': + yield (field.name, "0x%x" % self.val[field.name]) else: - name = field.name - val = self.val[field.name] - yield (name, format_nested(val)) + yield (field.name, format_nested(self.val[field.name])) pp_set.add_printer('zend_array', '^_zend_array$', ZendArrayPrettyPrinter)