check vector index out of range

This commit is contained in:
Yuichi Nishiwaki 2013-11-17 02:32:27 +09:00
parent 0690fbbdb4
commit 242a366cbf
1 changed files with 6 additions and 0 deletions

View File

@ -91,6 +91,9 @@ pic_vec_vector_ref(pic_state *pic)
pic_get_args(pic, "vi", &v, &k);
if (k < 0 || v->len <= k) {
pic_error(pic, "vector-ref: index out of range");
}
return v->data[k];
}
@ -103,6 +106,9 @@ pic_vec_vector_set(pic_state *pic)
pic_get_args(pic, "vio", &v, &k, &o);
if (k < 0 || v->len <= k) {
pic_error(pic, "vector-set!: index out of range");
}
v->data[k] = o;
return pic_false_value();
}