mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
sprintf.c: NULL as str
* sprintf.c (ruby_vsnprintf, ruby_snprintf): allow NULL as str, just count the expected buffer size. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59789 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6c3c48e3d5
commit
067d9e9ce9
3 changed files with 26 additions and 6 deletions
|
@ -90,6 +90,13 @@ printf_test_call(int argc, VALUE *argv, VALUE self)
|
|||
return rb_assoc_new(result, rb_usascii_str_new_cstr(format));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
snprintf_count(VALUE self, VALUE str)
|
||||
{
|
||||
int n = ruby_snprintf(NULL, 0, "%s", StringValueCStr(str));
|
||||
return INT2FIX(n);
|
||||
}
|
||||
|
||||
void
|
||||
Init_printf(void)
|
||||
{
|
||||
|
@ -98,4 +105,5 @@ Init_printf(void)
|
|||
rb_define_singleton_method(m, "v", printf_test_v, 1);
|
||||
rb_define_singleton_method(m, "q", printf_test_q, 1);
|
||||
rb_define_singleton_method(m, "call", printf_test_call, -1);
|
||||
rb_define_singleton_method(m, "sncount", snprintf_count, 1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue