Bug #20438
closedString format "%\n" and "%\0" does not raise format error
Description
"%" % 1
raises incomplete format specifier; use %% (double %) instead
"%=" % 1
raises malformed format string - %=
.
But "%\n" % 1
"%\0" % 1
does not raise error.
In sprintf.c
, \n
and \0
are explicitly accepted. Is this expected?
Some other language are:
Perl: Warns Invalid conversion in printf
. Just prints. "%d% " → "1% "
Python: Error ValueError: unsupported format character '?' (0xa)
with print("%\n" % 123)
PHP: Error Unknown format specifier
with sprintf("%\n", 3)
C, C++: Warns incomplete format specifier
. "%\n" → "\n"
, "%" → ""
, "% " → ""
sprintf("%f%\n",x)
and "%f%\n" % x
is used in some codes https://github.com/search?q=language%3ARuby+%22f%25%5Cn%22&type=code
Updated by nobu (Nobuyoshi Nakada) 4 months ago
- Has duplicate Bug #20439: Invalid string format with n$ flag is ignored in some case added
Updated by nobu (Nobuyoshi Nakada) 4 months ago
· Edited
"%\n"
has been treated as "%%"
since 554b989ba162, probably Tue Aug 6 01:12:32 1996 according to the commit log.
I don't know the reason.
Updated by nobu (Nobuyoshi Nakada) 4 months ago
- Related to Bug #13315: Single "%" at the end of `printf` format string appears in the result added
Updated by nobu (Nobuyoshi Nakada) 3 months ago
Updated by nobu (Nobuyoshi Nakada) 3 months ago
- Status changed from Open to Closed
Applied in changeset git|31c9a3a1d330606493e5e70aec3cd1a36d8c61a0.
[Bug #20438] Disallow "%\n" and "%\0"