1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

string.c: argument check

* string.c (rb_str_cat_cstr): check the argument as other `_cstr`
  functions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-04-17 05:23:00 +00:00
parent 37dffb599d
commit a0209e4845

View file

@ -484,6 +484,14 @@ rb_str_capacity(VALUE str)
}
}
static inline void
must_not_null(const char *ptr)
{
if (!ptr) {
rb_raise(rb_eArgError, "NULL pointer given");
}
}
static inline VALUE
str_alloc(VALUE klass)
{
@ -565,9 +573,7 @@ rb_enc_str_new(const char *ptr, long len, rb_encoding *enc)
VALUE
rb_str_new_cstr(const char *ptr)
{
if (!ptr) {
rb_raise(rb_eArgError, "NULL pointer given");
}
must_not_null(ptr);
return rb_str_new(ptr, strlen(ptr));
}
@ -582,9 +588,7 @@ rb_usascii_str_new_cstr(const char *ptr)
VALUE
rb_enc_str_new_cstr(const char *ptr, rb_encoding *enc)
{
if (!ptr) {
rb_raise(rb_eArgError, "NULL pointer given");
}
must_not_null(ptr);
if (rb_enc_mbminlen(enc) != 1) {
rb_raise(rb_eArgError, "wchar encoding given");
}
@ -2062,6 +2066,7 @@ rb_str_cat(VALUE str, const char *ptr, long len)
VALUE
rb_str_cat_cstr(VALUE str, const char *ptr)
{
must_not_null(ptr);
return rb_str_buf_cat(str, ptr, strlen(ptr));
}