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
Closed

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

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

Comments

@vicuna
Copy link

vicuna 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
Copy link
Author

vicuna 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
Copy link
Author

vicuna 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
Copy link
Author

vicuna commented Oct 15, 2009

Comment author: @damiendoligez

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

@vicuna
Copy link
Author

vicuna 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
Copy link
Author

vicuna 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
Labels
Projects
None yet
Development

No branches or pull requests

1 participant