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

Add small signed integers #51

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

brendanzab
Copy link
Contributor

This is an attempt to address some of the review comments on PR #49.

Closes #49

@brendanzab brendanzab changed the title Small signed integers fixes Add small signed integers Nov 11, 2024
Comment on lines +118 to +125
assert (check "-128" (to_string (of_int 128))); (* FIXME: This value seems strange? *)
assert (check "-128" (to_string (of_int (-128))));
assert (check "127" (to_string (of_int (-129)))); (* FIXME: This value seems strange? *)
assert (check "-1" (to_string (of_int (-1))));
assert (check "f" (to_hexstring (of_int (0xf))));
assert (check "7f" (to_hexstring max_int));
assert (check "80" (to_hexstring min_int));
assert (check "81" (to_hexstring (of_int (-0x7f)))); (* FIXME: This value seems strange? *)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found some of these results strange, but I guess this is more a result of of_int not doing any bounds checking? I can remove the FIXMEs if this is the expected behavior.

@brendanzab brendanzab force-pushed the small-signed-integers-fixes branch from feb654c to d877b80 Compare November 11, 2024 08:44
@brendanzab
Copy link
Contributor Author

brendanzab commented Nov 17, 2024

Just wondering if I could get approval to run the tests for this PR?

@brendanzab
Copy link
Contributor Author

Oh dear - there seems to be some buffer overflows on non-macOS platforms… I’m assuming from the original code? This might be a bit beyond me. 😬

@brendanzab
Copy link
Contributor Author

It won’t be as fast, but in the interim I could just implement small integer parsing in terms of the existing int_of_string implementation?

  let of_string s =
    let x = 
      try int_of_string s with 
      | Failure _ -> failwith "Int8.of_string"
    in
    if x when x < min_value || x > max_value then
      failwith "Int8.of_string"
    else x

@yallop
Copy link
Owner

yallop commented Nov 25, 2024

The buffer overflows are due to a bug in the C code for printing the hex string representation of small integers (https://github.com/yallop/ocaml-integers/pull/51/files#diff-37aa1176c737be854df50dc3979f0cdfc6d74f3c060d2047cdf4bb4806bb6566R108-R114), which doesn't allocate enough space to hold the printed representation for negative numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants