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

fix overflow crash when displaying ETA #555

Merged
merged 1 commit into from Jun 27, 2023

Conversation

conradoplg
Copy link
Contributor

Possible fix for #554, but I wasn't thorough checking for other possible sources of overflow (in particular in the ETA calculation itself, though from a glance it seems OK)

Copy link
Collaborator

@djc djc left a comment

Choose a reason for hiding this comment

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

Thanks for looking at this!

@@ -77,7 +77,7 @@ impl fmt::Display for HumanDuration {
for (i, &(cur, _, _)) in UNITS.iter().enumerate() {
idx = i;
match UNITS.get(i + 1) {
Some(&next) if self.0 + next.0 / 2 >= cur + cur / 2 => break,
Some(&next) if self.0.saturating_add(next.0 / 2) >= cur + cur / 2 => break,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we also need saturating_add() for cur here?

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 don't think so, cur comes from a list of constants and none of them make it overflow.

@djc djc merged commit 1bf2cce into console-rs:main Jun 27, 2023
9 checks passed
@djc
Copy link
Collaborator

djc commented Jun 27, 2023

Right, thanks!

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.

None yet

2 participants