Project

General

Profile

Bug #9861

BSD_vfprintf precsion doesn't work at shorter string

Added by nobu (Nobuyoshi Nakada) about 5 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
1.4.0 or later
[ruby-core:62737]

Description

ruby_snprintfなどで"%s"に精度を指定してその精度よりも短い文字列を渡すと、本来の長さが無視されて精度まで'\0'が詰められます。

/* t.c */
#include <ruby/ruby.h>

int main(void)
{
    char buf[26];
    ruby_snprintf(buf, sizeof(buf), "%.2s", "s");
    printf("[%.2x][%.2x][%.2x]\n", buf[0], buf[1], buf[2]);
    return 0;
}
$ make t LDLIBS='$(LIBRUBYARG_STATIC) $(LIBS)'
$ ./t
[73][00][00]

最初のmissing/vsnprintf.cからあるようなので、1.4.0以降すべてのバージョンにあるバグだと思います。

Associated revisions

Revision bae87a47
Added by nobu (Nobuyoshi Nakada) about 5 years ago

vsnprintf.c: fix string precision

  • vsnprintf.c (BSD_vfprintf): fix string width when precision is given. as the result of memchr is NULL or its offset from the start cannot exceed the size, the comparison was always false. [ruby-core:62737] [Bug #9861]

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

Revision 46098
Added by nobu (Nobuyoshi Nakada) about 5 years ago

vsnprintf.c: fix string precision

  • vsnprintf.c (BSD_vfprintf): fix string width when precision is given. as the result of memchr is NULL or its offset from the start cannot exceed the size, the comparison was always false. [ruby-core:62737] [Bug #9861]

Revision 46098
Added by nobu (Nobuyoshi Nakada) about 5 years ago

vsnprintf.c: fix string precision

  • vsnprintf.c (BSD_vfprintf): fix string width when precision is given. as the result of memchr is NULL or its offset from the start cannot exceed the size, the comparison was always false. [ruby-core:62737] [Bug #9861]

Revision 46098
Added by nobu (Nobuyoshi Nakada) about 5 years ago

vsnprintf.c: fix string precision

  • vsnprintf.c (BSD_vfprintf): fix string width when precision is given. as the result of memchr is NULL or its offset from the start cannot exceed the size, the comparison was always false. [ruby-core:62737] [Bug #9861]

Revision 46098
Added by nobu (Nobuyoshi Nakada) about 5 years ago

vsnprintf.c: fix string precision

  • vsnprintf.c (BSD_vfprintf): fix string width when precision is given. as the result of memchr is NULL or its offset from the start cannot exceed the size, the comparison was always false. [ruby-core:62737] [Bug #9861]

Revision 46098
Added by nobu (Nobuyoshi Nakada) about 5 years ago

vsnprintf.c: fix string precision

  • vsnprintf.c (BSD_vfprintf): fix string width when precision is given. as the result of memchr is NULL or its offset from the start cannot exceed the size, the comparison was always false. [ruby-core:62737] [Bug #9861]

Revision 46098
Added by nobu (Nobuyoshi Nakada) about 5 years ago

vsnprintf.c: fix string precision

  • vsnprintf.c (BSD_vfprintf): fix string width when precision is given. as the result of memchr is NULL or its offset from the start cannot exceed the size, the comparison was always false. [ruby-core:62737] [Bug #9861]

Revision 4e057b91
Added by usa (Usaku NAKAMURA) almost 5 years ago

merge revision(s) 46098: [Backport #9861]

    * vsnprintf.c (BSD_vfprintf): fix string width when precision is
      given.  as the result of `memchr` is NULL or its offset from the
      start cannot exceed the size, the comparison was always false.
      [ruby-core:62737] [Bug #9861]

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

Revision 46582
Added by usa (Usaku NAKAMURA) almost 5 years ago

merge revision(s) 46098: [Backport #9861]

* vsnprintf.c (BSD_vfprintf): fix string width when precision is
  given.  as the result of `memchr` is NULL or its offset from the
  start cannot exceed the size, the comparison was always false.
  [ruby-core:62737] [Bug #9861]

Revision 0caeba64
Added by nagachika (Tomoyuki Chikanaga) almost 5 years ago

merge revision(s) r46098: [Backport #9861]

    * vsnprintf.c (BSD_vfprintf): fix string width when precision is
      given.  as the result of `memchr` is NULL or its offset from the
      start cannot exceed the size, the comparison was always false.
      [ruby-core:62737] [Bug #9861]

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

Revision 46611
Added by nagachika (Tomoyuki Chikanaga) almost 5 years ago

merge revision(s) r46098: [Backport #9861]

* vsnprintf.c (BSD_vfprintf): fix string width when precision is
  given.  as the result of `memchr` is NULL or its offset from the
  start cannot exceed the size, the comparison was always false.
  [ruby-core:62737] [Bug #9861]

History

Updated by nobu (Nobuyoshi Nakada) about 5 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

Applied in changeset r46098.


vsnprintf.c: fix string precision

  • vsnprintf.c (BSD_vfprintf): fix string width when precision is given. as the result of memchr is NULL or its offset from the start cannot exceed the size, the comparison was always false. [ruby-core:62737] [Bug #9861]

Updated by usa (Usaku NAKAMURA) almost 5 years ago

backported into ruby_2_0_0 at r46582.

Updated by usa (Usaku NAKAMURA) almost 5 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED to 2.0.0: DONE, 2.1: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) almost 5 years ago

  • Backport changed from 2.0.0: DONE, 2.1: REQUIRED to 2.0.0: DONE, 2.1: DONE

Backported into ruby_2_1 branch at r46611.

Also available in: Atom PDF