Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'index out of bound' check too early? #4892

Closed
vicuna opened this issue Oct 14, 2009 · 5 comments

Comments

Projects
None yet
1 participant
@vicuna
Copy link

commented Oct 14, 2009

Original bug ID: 4892
Reporter: @alainfrisch
Status: closed (set by @xavierleroy on 2013-08-31T10:48:44Z)
Resolution: fixed
Priority: low
Severity: minor
Fixed in version: 4.00.0+dev
Category: ~DO NOT USE (was: OCaml general)
Related to: #2719
Monitored by: @ygrek

Bug description

One expects arguments of a function call to be evaluated before the function is called. This is not the case in the following expression, using the native code compiler:

let () = Array.set [| |] 0 (print_endline "XXX")

The exception Invalid_argument("index out of bounds") is raised before the argument (print_endline "XXX") is evaluated.

@vicuna

This comment has been minimized.

Copy link
Author

commented Oct 15, 2009

Comment author: ertai

Why do you expects the arguments of this function to be all evaluated before doing the update.

Array.set could morally be seen as:

let set array index =
...bound...check... array index;
fun v -> ...update...code...

Which have the nice property of checking once the bounds:

let isetter = Array.set array i in
let rec ... k = ... isetter k ...

However the reports is still worthy since the behavior should be the same in bytecode.

@vicuna

This comment has been minimized.

Copy link
Author

commented Oct 15, 2009

Comment author: @alainfrisch

Why do you expects the arguments of this function to be all evaluated before
doing the update.

Because, in a call-by-value language, as I said, one expects arguments of a function call to be evaluated before the function is called.

@vicuna

This comment has been minimized.

Copy link
Author

commented Oct 15, 2009

Comment author: @damiendoligez

This bug seems to be a kind of dual to #2719...

@vicuna

This comment has been minimized.

Copy link
Author

commented Oct 20, 2009

Comment author: @alainfrisch

The bug is in Cmmgen.transl_prim_3 and the fix is straightforward (always bind "newval" to arg3).

@vicuna

This comment has been minimized.

Copy link
Author

commented Mar 14, 2012

Comment author: @xavierleroy

Fixed in 4.00 release branch (r12237) and in trunk (r12238).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.