You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 7690 Reporter:@oandrieu Assigned to:@nojb Status: resolved (set by @nojb on 2017-12-19T14:24:12Z) Resolution: fixed Priority: normal Severity: minor Version: 4.03.0 Category: standard library Monitored by:@nojb@gasche@dra27
Bug description
There are some overflow issues with the exponent computations in caml_float_of_hex, which results in some invalid conversions. The integer exp variable overflows, which results in the call to ldexp to overflow when it should underflow (and vice versa).
The test "if (e < INT_MIN || e > INT_MAX) return -1;" is ineffective on Win64 since int and long have the same size there: this results in some difference in behavior between win64 and linux.
And (minor point), the function accept spaces between the 'p' and the exponent digits, whereas strtod and the C99 syntax do not allow spaces there.
Steps to reproduce
$ cat f.ml
let hexstring_of_float x =
Printf.sprintf "%h" x
let () =
let s =
try hexstring_of_float (float_of_string Sys.argv.(1))
with _ -> "invalid" in
print_endline s
$ ocamlopt.opt f.ml
$ ./a.out 0x1.0p-2147483648
infinity
$ ./a.out 0x123456789ABCDEF0p2147483647
0x0p+0
$ ./a.out 0x1p2147483648
-> invalid on linux64
-> infinity on win64
$ ./a.out '0x1p 1'
0x1p+1
The text was updated successfully, but these errors were encountered:
Definitely the overflow one needs fixing; a GPR would be much appreciated!
Regarding the second one, I am not sure if it is a bug or not at the moment.
Original bug ID: 7690
Reporter: @oandrieu
Assigned to: @nojb
Status: resolved (set by @nojb on 2017-12-19T14:24:12Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.03.0
Category: standard library
Monitored by: @nojb @gasche @dra27
Bug description
There are some overflow issues with the exponent computations in caml_float_of_hex, which results in some invalid conversions. The integer exp variable overflows, which results in the call to ldexp to overflow when it should underflow (and vice versa).
The test "if (e < INT_MIN || e > INT_MAX) return -1;" is ineffective on Win64 since int and long have the same size there: this results in some difference in behavior between win64 and linux.
And (minor point), the function accept spaces between the 'p' and the exponent digits, whereas strtod and the C99 syntax do not allow spaces there.
Steps to reproduce
$ cat f.ml
let hexstring_of_float x =
Printf.sprintf "%h" x
let () =
let s =
try hexstring_of_float (float_of_string Sys.argv.(1))
with _ -> "invalid" in
print_endline s
$ ocamlopt.opt f.ml
$ ./a.out 0x1.0p-2147483648
infinity
$ ./a.out 0x123456789ABCDEF0p2147483647
0x0p+0
$ ./a.out 0x1p2147483648
-> invalid on linux64
-> infinity on win64
$ ./a.out '0x1p 1'
0x1p+1
The text was updated successfully, but these errors were encountered: