Bug #13315
closed
Single "%" at the end of `printf` format string appears in the result
Added by nobu (Nobuyoshi Nakada) over 7 years ago.
Updated over 7 years ago.
Description
Is this intentional?
printf("%") #=> "%"
printf
in glibc does print nothing, gcc warns though.
#include <stdio.h>
int main(void)
{
printf("%");
return 0;
}
$ gcc fmt.c && ./a.out
fmt.c: In function ‘main’:
fmt.c:5:10: warning: spurious trailing ‘%’ in format [-Wformat=]
printf("%");
^
printf
command of bash errs.
$ printf "%"
-bash: printf: `%': missing format character
- Assignee set to matz (Yukihiro Matsumoto)
Matz, is this intentional?
- Status changed from Open to Assigned
When I wrote the original code, it was intentional, but without any specific reason.
It's OK for me to raise an error for this case.
Matz.
- Assignee changed from matz (Yukihiro Matsumoto) to Eregon (Benoit Daloze)
- Status changed from Assigned to Closed
Applied in changeset trunk|r58890.
Raise ArgumentError if sprintf format string ends with %
- Add tests and specs. See ruby/spec#401.
Patch by Yuta Iwama and Shintaro Morikawa.
[ruby-core:80153] [Bug #13315] [Fix GH-1560]
- Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: WONTFIX, 2.3: WONTFIX, 2.4: UNKNOWN
- Related to Bug #20439: Invalid string format with n$ flag is ignored in some case added
- Related to Bug #20438: String format "%\n" and "%\0" does not raise format error added
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0