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 panic when formatting TimeStamp::MIN #838

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

CryZe
Copy link
Collaborator

@CryZe CryZe commented Aug 28, 2024

In order to print the minus sign of times, we detect the need for the minus sign, print it and then print the absolute value of the time. However, integers have a minimum value of which the absolute value is larger than the maximum value of the integer. So for example i8 has a minimum value of -128 and a maximum value of 127. The absolute value therefore can't be represented. This caused a panic when formatting TimeStamp::MIN when overflow checks are enabled, such as when compiling with the debug profile.

There was also a big lack of tests for the formatting of times. Tests are now included for all the important cases.

In order to print the minus sign of times, we detect the need for the
minus sign, print it and then print the absolute value of the time.
However, integers have a minimum value that is one less than the
absolute value of the maximum value. This means that the minimum value
of a signed integer cannot be negated. This caused a panic when
formatting `TimeStamp::MIN` when overflow checks are enabled, such as
when compiling with the debug profile.

There was also a big lack of tests for the formatting of times. Tests
are now included for all the important cases.
@CryZe CryZe added bug There is a bug. enhancement An improvement for livesplit-core. code quality Affects the quality of the code. labels Aug 28, 2024
@CryZe CryZe added this to the v0.14 milestone Aug 28, 2024
@CryZe CryZe enabled auto-merge (squash) August 28, 2024 16:30
@CryZe CryZe merged commit b0ff646 into LiveSplit:master Aug 28, 2024
70 checks passed
@CryZe CryZe deleted the formatting-min branch September 5, 2024 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug There is a bug. code quality Affects the quality of the code. enhancement An improvement for livesplit-core.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant