Skip to content

Commit 9ebcce6

Browse files
committed
Runtime: caml_obj_truncate should raise on invalid input
1 parent d55d24a commit 9ebcce6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

runtime/stdlib.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,13 @@ function caml_obj_dup (x) {
215215
return a;
216216
}
217217
//Provides: caml_obj_truncate (mutable, const)
218-
function caml_obj_truncate (x, s) { x.length = s + 1; return 0; }
218+
//Requires: caml_invalid_argument
219+
function caml_obj_truncate (x, s) {
220+
if (s<=0 || s + 1 > x.length)
221+
caml_invalid_argument ("Obj.truncate");
222+
if (x.length != s + 1) x.length = s + 1;
223+
return 0;
224+
}
219225

220226
//Provides: caml_lazy_make_forward const (const)
221227
function caml_lazy_make_forward (v) { return [250, v]; }

0 commit comments

Comments
 (0)