ruby-changes:33529
From: nobu <ko1@a...>
Date: Thu, 17 Apr 2014 14:23:08 +0900 (JST)
Subject: [ruby-changes:33529] nobu:r45610 (trunk): string.c: argument check
nobu 2014-04-17 14:23:00 +0900 (Thu, 17 Apr 2014) New Revision: 45610 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45610 Log: string.c: argument check * string.c (rb_str_cat_cstr): check the argument as other `_cstr` functions. Modified files: trunk/string.c Index: string.c =================================================================== --- string.c (revision 45609) +++ string.c (revision 45610) @@ -484,6 +484,14 @@ rb_str_capacity(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L484 } } +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 https://github.com/ruby/ruby/blob/trunk/string.c#L573 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) https://github.com/ruby/ruby/blob/trunk/string.c#L588 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, l https://github.com/ruby/ruby/blob/trunk/string.c#L2066 VALUE rb_str_cat_cstr(VALUE str, const char *ptr) { + must_not_null(ptr); return rb_str_buf_cat(str, ptr, strlen(ptr)); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/