diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-04-17 05:23:00 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-04-17 05:23:00 +0000 |
commit | a0209e4845b01a625b25cc34b11b23c64c478619 (patch) | |
tree | e71439977ce9f48cf44c476e37924cc221f57062 /string.c | |
parent | 37dffb599de6ad056c686f41881e9967dee4418e (diff) |
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
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -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)); } |