Skip to content

Potential bug on extract int64 #38

@Yu-zh

Description

@Yu-zh

It seems that the fast path and slow path for extracting int64 in littleendian are inconsistent. I have the following program, where I expect f and g to print the result.

let f bits =
  match%bitstring bits with
  | {| a:4; b:60:littleendian; _:-1:bitstring |} ->
    print_string (Int.to_string a);
    print_endline "";
    print_string (Int64.to_string b);
    print_endline ""
  | {|_|} -> failwith "run_test5"
;;

let g bits =
  match%bitstring bits with
  | {| b:60:littleendian; a:4; _:-1:bitstring |} ->
    print_string (Int.to_string a);
    print_endline "";
    print_string (Int64.to_string b);
    print_endline ""
  | {|_|} -> failwith "run_test6"
;;

let () =
  f (Bitstring.bitstring_of_string "\xA0\x00\x00\x00\x00\x00\x00\x00");
  g (Bitstring.bitstring_of_string "\x00\x00\x00\x00\x00\x00\x00\x0A")
;;

However, the result I got is:

10                                 
0
10
720575940379279360

It seems the fast path for extracting int64 does not properly handle the case when reading less than 64 bit. Or did I misunderstand anything?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions