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

Bug is List.sort #2520

Closed
vicuna opened this issue Jul 6, 2000 · 1 comment
Closed

Bug is List.sort #2520

vicuna opened this issue Jul 6, 2000 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Jul 6, 2000

Original bug ID: 156
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Hello,
The following program crashes:

let _ = 
  let a = Array.init 100 (fun _ -> Random.float 1.0) in
  let l = Array.to_list a in
  let l = List.sort compare l in
  ()

Fatal error: uncaught exception Invalid_argument("Array.get")

It must be a bug in List.sort, because with Array.sort this works fine.
I may add a request, as has been discussed in the list recently, to add
an optional feature that shows where the exception was thrown. This
(new) bug has occured in a 100,000 lines of code system (Ensemble). It is
difficult to find a bug in such a large system without language level
help.

Thanks,
Ohad.

@vicuna
Copy link
Author

vicuna commented Jul 8, 2000

Comment author: administrator

From: orodeh@cs.huji.ac.il

let _ =
let a = Array.init 100 (fun _ -> Random.float 1.0) in
let l = Array.to_list a in
let l = List.sort compare l in
()

Fatal error: uncaught exception Invalid_argument("Array.get")

It must be a bug in List.sort, because with Array.sort this works fine.

This is a bug in Obj.truncate, which makes List.sort fail on all lists
of floats (except the empty list), but only on 32-bit machines. Many
thanks for finding and reporting the bug. I'm including a patch at the
end of this mail.

-- Damien

Index: byterun/obj.c
===================================================================
RCS file: /net/pauillac/caml/repository/csl/byterun/obj.c,v
retrieving revision 1.13
diff -c -r1.13 obj.c
*** obj.c       2000/04/03 08:34:22     1.13
--- obj.c       2000/07/08 18:33:33
***************
*** 102,107 ****
--- 102,109 ----
    mlsize_t wosize = Wosize_hd (hd);
    mlsize_t i;
  
+   if (tag == Double_array_tag) new_wosize *= Double_wosize;  /* #2520 */
+ 
    if (new_wosize <= 0 || new_wosize > wosize) 
      invalid_argument ("Obj.truncate");
    if (new_wosize == wosize) return Val_unit;

@vicuna vicuna closed this as completed Jul 8, 2000
@vicuna vicuna added the bug label Mar 19, 2019
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