Skip to content

Commit

Permalink
Merge pull request mruby#1001 from monaka/pr-add-type-check-in-mrb_st…
Browse files Browse the repository at this point in the history
…r_to_cstr

Add the type check in mrb_str_to_cstr().
  • Loading branch information
matz committed Mar 14, 2013
2 parents 0f7cd2e + fe057fa commit 0739960
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ mrb_str_to_cstr(mrb_state *mrb, mrb_value str0)
{
mrb_value str;

if (!mrb_string_p(str0)) {
mrb_raise(mrb, E_TYPE_ERROR, "expected String");
}

str = mrb_str_new(mrb, RSTRING_PTR(str0), RSTRING_LEN(str0));
if (strlen(RSTRING_PTR(str)) != RSTRING_LEN(str)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "string contains null byte");
Expand Down

0 comments on commit 0739960

Please sign in to comment.