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

of_string for unsigned integers does not raise exception on negative inputs #47

Open
anton-trunov opened this issue Oct 3, 2020 · 2 comments

Comments

@anton-trunov
Copy link

Actual behavior

Here is a toplevel session:

μ> #require "stdint";;
μ> "-1" |> Stdint.Uint128.of_string |> Stdint.Uint128.to_string;;
- : string = "340282366920938463463374607431768211455"

Basically, this is the maximum 128-bit unsigned integer. It behaves the same for the rest of bit widths.

Expected behavior

Raises an exception according to the description here:

ocaml-stdint/lib/stdint.mli

Lines 292 to 297 in 48f97cd

(** Convert the given string to an integer of type [t].
The string is read in decimal (by default) or in hexadecimal, octal
or binary if the string begins with [0x], [0o] or [0b] respectively.
Raise [Failure "*_of_string"] if the given string is not a valid
representation of an integer, or if the integer represented exceeds
the range of integers representable in type [t]. *)
:

@rgrinberg
Copy link
Collaborator

Yes, that seems confusing. @rixed what do you think?

@rixed
Copy link
Contributor

rixed commented Oct 5, 2020

Given the quoted documentation and the fact that other Int modules seem to raise an exception (although not Failure but Invalid_arg, which looks better to me), I'd say that Uint128.of_string should indeed raise.
I would favor if all of the of_string functions would raise the same exception BTW.

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

No branches or pull requests

3 participants