Actions
Bug #13315
closedSingle "%" at the end of `printf` format string appears in the result
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
Updated by morishin (Shintaro Morikawa) over 7 years ago
I believe this is not intentional, so created a pull-request on GitHub.
https://github.com/ruby/ruby/pull/1560
This change makes ruby raise error for printf("%")
though C just shows warning because this change will drop displayed "%" silently for developers if this shows just warning instead of raising error.
I updated rubyspec too.
https://github.com/ruby/spec/issues/401
Updated by sorah (Sorah Fukumori) over 7 years ago
- Assignee set to matz (Yukihiro Matsumoto)
Matz, is this intentional?
Updated by shyouhei (Shyouhei Urabe) over 7 years ago
- Status changed from Open to Assigned
Updated by matz (Yukihiro Matsumoto) over 7 years ago
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.
Updated by Eregon (Benoit Daloze) over 7 years ago
- Assignee changed from matz (Yukihiro Matsumoto) to Eregon (Benoit Daloze)
Updated by Eregon (Benoit Daloze) over 7 years ago
- 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]
Updated by usa (Usaku NAKAMURA) over 7 years ago
- Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: WONTFIX, 2.3: WONTFIX, 2.4: UNKNOWN
Updated by nobu (Nobuyoshi Nakada) 8 months ago
- Related to Bug #20439: Invalid string format with n$ flag is ignored in some case added
Updated by nobu (Nobuyoshi Nakada) 8 months ago
- Related to Bug #20438: String format "%\n" and "%\0" does not raise format error added
Actions
Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0