Merge branch 'issue-316'

This commit is contained in:
Yuichi Nishiwaki 2015-12-30 01:08:39 +09:00
commit 03e1ef1753
1 changed files with 10 additions and 5 deletions

View File

@ -519,17 +519,22 @@ static pic_value
pic_str_string_copy(pic_state *pic) pic_str_string_copy(pic_state *pic)
{ {
pic_str *str; pic_str *str;
int n, start, end; int n, start, end, len;
n = pic_get_args(pic, "s|ii", &str, &start, &end); n = pic_get_args(pic, "s|ii", &str, &start, &end);
len = pic_str_len(str);
switch (n) { switch (n) {
case 1: case 1:
start = 0; start = 0;
case 2: case 2:
end = pic_str_len(str); end = len;
} }
if (start < 0 || end > len || end < start)
pic_errorf(pic, "string-copy: invalid index");
return pic_obj_value(pic_str_sub(pic, str, start, end)); return pic_obj_value(pic_str_sub(pic, str, start, end));
} }