[GIT-PULLS] [php-src] PR #22930: PoC: php_printf: introduce %pS to replace custom specifier %S
[email protected] (arnaud-lb) Thu, 30 Jul 2026 08:32:59 +0000
| Newsgroups | php.git-pulls |
|---|---|
| Message-ID | <[email protected]> |
Pull Request: https://github.com/php/php-src/pull/22930 Author: arnaud-lb The string formater supports custom format specifiers such as `S` (`zend_string*`), but format strings using these specifiers do not pass the compiler's type checks that are performed on functions tagged with `ZEND_ATTRIBUTE_FORMAT`. As a result we can not use these specifiers without resorting to workarounds: * Use variants of formatting functions that do not have `ZEND_ATTRIBUTE_FORMAT` ([example](https://github.com/php/php-src/blob/0b5d9801ec3b53e84388239a5b9f85d005318b64/Zend/zend_compile.c#L8586-L8587)) * Or declare the format string separately ([example](https://github.com/php/php-src/blob/edc169e7705d5e4411865e9be92b50e82be78f4e/Zend/zend_partial.c#L680)) Here I propose to re-introduce `%S` as `%pS`. The compiler will only see a `%p` specifier followed by the ordinary literal character `S`, so it will be happy about an argument of type `zend_string*`. This trick is used in the Linux kernel, and can be applied to more custom specifiers.