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

CP-50259 simplify parsing size with kib, mib, etc suffix #5819

Merged
merged 1 commit into from
Jul 12, 2024

Conversation

lindig
Copy link
Contributor

@lindig lindig commented Jul 12, 2024

Simplify the implementation.

record_failure
"Failed to parse field '%s': expecting an integer (possibly with suffix \
KiB, MiB, GiB, TiB), got '%s'"
field x

(* Vincent's random mac utils *)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this Vincent is here anymore, do we want to keep this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't have to. I was not not sure what this is about.

Copy link
Member

Choose a reason for hiding this comment

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

He's sitting right next to me, though 😅

Copy link
Member

Choose a reason for hiding this comment

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

Definitely a different Vincent ;)

Comment on lines -1094 to -1102
let alldigit = ref true and i = ref (String.length s - 1) in
while !alldigit && !i > 0 do
alldigit := Astring.Char.Ascii.is_digit s.[!i] ;
decr i
done ;
if !alldigit then
record_failure
"Failed to parse field '%s': number too big (maximum = %Ld TiB)" field
max_size_TiB
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it not important anymore to distinguish between "not an integer - couldn't parse" and "integer - but too big"? Additionally, we could overflow above when multiplying ** 1024 several times, do we want to catch and report that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Overflow is detected and results in an exception, which is caught. That number is incredibly large, though.

Simplify the implementation.

Signed-off-by: Christian Lindig <christian.lindig@cloud.com>
GiB or TiB)"
field x
in
(* FIXME: detect overflow *)
Copy link
Contributor

Choose a reason for hiding this comment

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

see comment above re: overflow

@lindig lindig force-pushed the private/christianlin/CP-50259 branch from c79a3fc to e1fd10b Compare July 12, 2024 13:48
@lindig lindig merged commit 2e59029 into xapi-project:master Jul 12, 2024
15 checks passed
@robhoes
Copy link
Member

robhoes commented Jul 12, 2024

Didn't the old function accept a space between the number and suffix, while the new one does not?

@lindig
Copy link
Contributor Author

lindig commented Jul 12, 2024

Reading the code, I believe you are right that the splitting allows a space. It's a bit awkward though, because this gets in the way of shell splitting words - so you would have quote that in a shell. Let me see if this can be accommodated.

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.

4 participants