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

AMD64: output_binary_int/input_binary_int mess up the int. #8433

Closed
vicuna opened this issue Jan 4, 2004 · 1 comment
Closed

AMD64: output_binary_int/input_binary_int mess up the int. #8433

vicuna opened this issue Jan 4, 2004 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Jan 4, 2004

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

Bug description

Full_Name: Aleksey Nogin
Version: 3.07+12 (2004-01-03) from CVS
OS: Fedora Core Development
Submission from: charter-242-037.caltech.edu (131.215.242.37)

Summary: It seems that on AMD64 the input_binary_int function is capable of
reading an integer that's different from what was passed to output_binary_int.

One would expect that teh following code:

let f = open_out_bin "/tmp/foo";;
output_binary_int f i;;
close_out f;;
let f = open_in_bin "/tmp/foo";;
let i' = input_binary_int f;;
close_in f;;
i' = i;;

Would output "true" for any int i. However this is not the case on AMD64:

matrix41:~> ocaml
Objective Caml version 3.07+12 (2004-01-03)

let i = 0x89ac12bd;;

val i : int = 2309755581

let f = open_out_bin "/tmp/foo";;

val f : out_channel =

output_binary_int f i;;

  • : unit = ()

close_out f;;

  • : unit = ()

let f = open_in_bin "/tmp/foo";;

val f : in_channel =

let i' = input_binary_int f;;

val i' : int = -1985211715

close_in f;;

  • : unit = ()

i' == i;;

  • : bool = false

i' = i;;

  • : bool = false

while the same thing works "correctly" on a 32-bit machine - at least with
3.06:

    Objective Caml version 3.06

let i = 0x89ac12bd;;

val i : int = 162271933

let f = open_out_bin "/tmp/foo";;

val f : out_channel =

output_binary_int f i;;

  • : unit = ()

close_out f;;

  • : unit = ()

let f = open_in_bin "/tmp/foo";;

val f : in_channel =

let i' = input_binary_int f;;

val i' : int = 162271933

close_in f;;

  • : unit = ()

i' = i;;

  • : bool = true

On another 32-bit machine:

   Objective Caml version 3.07+7 (2003-12-17)

let i = 0x89ac12bd;;

Integer literal exceeds the range of representable integers of type int

Which is IMO pretty reasonable.

@vicuna
Copy link
Author

vicuna commented Apr 18, 2004

Comment author: administrator

{output,input}_binary_int use 32-bit signed data format, even on 64-bit
platforms, hence observed behavior. Documented this behavior 2004-04-18, XL.

@vicuna vicuna closed this as completed Apr 18, 2004
@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