Bug #13315


Single "%" at the end of `printf` format string appears in the result

Added by nobu (Nobuyoshi Nakada) over 4 years ago. Updated over 4 years ago.

Target version:


Is this intentional?

printf("%") #=> "%"

printf in glibc does print nothing, gcc warns though.

#include <stdio.h>

int main(void)
  return 0;
$ gcc fmt.c && ./a.out 
fmt.c: In function ‘main’:
fmt.c:5:10: warning: spurious trailing ‘%’ in format [-Wformat=]

printf command of bash errs.

$ printf "%"
-bash: printf: `%': missing format character

Updated by morishin (Shintaro Morikawa) over 4 years ago

I believe this is not intentional, so created a pull-request on GitHub.

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.

Updated by sorah (Sorah Fukumori) over 4 years ago

  • Assignee set to matz (Yukihiro Matsumoto)

Matz, is this intentional?

Actions #3

Updated by shyouhei (Shyouhei Urabe) over 4 years ago

  • Status changed from Open to Assigned

Updated by matz (Yukihiro Matsumoto) over 4 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.


Updated by Eregon (Benoit Daloze) over 4 years ago

  • Assignee changed from matz (Yukihiro Matsumoto) to Eregon (Benoit Daloze)
Actions #6

Updated by Eregon (Benoit Daloze) over 4 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]
Actions #7

Updated by usa (Usaku NAKAMURA) over 4 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: WONTFIX, 2.3: WONTFIX, 2.4: UNKNOWN

Also available in: Atom PDF