Project

General

Profile

Actions

Bug #13315

closed

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

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

Status:
Closed
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

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

  • Assignee set to matz (Yukihiro Matsumoto)

Matz, is this intentional?

Actions #3

Updated by shyouhei (Shyouhei Urabe) almost 7 years ago

  • Status changed from Open to Assigned

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

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

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

Updated by usa (Usaku NAKAMURA) over 6 years ago

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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0