summaryrefslogtreecommitdiff
path: root/ext/-test-
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-09 09:16:59 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-09 09:16:59 +0000
commit067d9e9ce97dd42b8b13eef10031b0fa9cf23a1f (patch)
tree934f07816670ae9286f399b18f9b8b78c495bc16 /ext/-test-
parent6c3c48e3d569a40774a14a5bfbebf3fc72874de0 (diff)
downloadbundler-067d9e9ce97dd42b8b13eef10031b0fa9cf23a1f.tar.gz
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
Diffstat (limited to 'ext/-test-')
-rw-r--r--ext/-test-/printf/printf.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/ext/-test-/printf/printf.c b/ext/-test-/printf/printf.c
index 666f5592e5..e793bb7a48 100644
--- a/ext/-test-/printf/printf.c
+++ b/ext/-test-/printf/printf.c
@@ -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);
}