Project

General

Profile

Bug #13315

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

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

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:80153]

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

Associated revisions

Revision fd8df3ab
Added by Eregon (Benoit Daloze) over 2 years ago

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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58890 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 58890
Added by Eregon (Benoit Daloze) over 2 years ago

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]

Revision 58890
Added by Eregon (Benoit Daloze) over 2 years ago

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]

Revision 58890
Added by Eregon (Benoit Daloze) over 2 years ago

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]

Revision c854fde3
Added by nobu (Nobuyoshi Nakada) over 2 years ago

sprintf.c: remove redundant condition

  • sprintf.c (rb_str_format): when t + 1 == end (or t < end), *t == '%' is always true. [ruby-core:80153] [Bug #13315]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 58898
Added by nobu (Nobuyoshi Nakada) over 2 years ago

sprintf.c: remove redundant condition

  • sprintf.c (rb_str_format): when t + 1 == end (or t < end), *t == '%' is always true. [ruby-core:80153] [Bug #13315]

Revision 58898
Added by nobu (Nobuyoshi Nakada) over 2 years ago

sprintf.c: remove redundant condition

  • sprintf.c (rb_str_format): when t + 1 == end (or t < end), *t == '%' is always true. [ruby-core:80153] [Bug #13315]

Revision 58898
Added by nobu (Nobuyoshi Nakada) over 2 years ago

sprintf.c: remove redundant condition

  • sprintf.c (rb_str_format): when t + 1 == end (or t < end), *t == '%' is always true. [ruby-core:80153] [Bug #13315]

History

Updated by morishin (Shintaro Morikawa) over 2 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 2 years ago

  • Assignee set to matz (Yukihiro Matsumoto)

Matz, is this intentional?

#3

Updated by shyouhei (Shyouhei Urabe) over 2 years ago

  • Status changed from Open to Assigned

Updated by matz (Yukihiro Matsumoto) over 2 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 2 years ago

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

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

Updated by usa (Usaku NAKAMURA) about 2 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