Repository navigation
fix: show 1.0 MB instead of 1024.0 kB in ByteCountDecimal - #1414
Merged
Merged
Conversation
The unit is chosen with integer division, but the value is then printed with %.1f, so sizes just below a unit boundary were shown as 1024.0 of the smaller unit, e.g. 1048575 bytes as "1024.0 kB" in the send and receive messages. When the rounded value is 1024.0, move up one unit.
Owner
|
thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ByteCountDecimalpicks the unit with integer division and then prints the value with%.1f, so a size just below a unit boundary is shown as 1024.0 of the smaller unit. For example 1048575 bytes:n = 1048575 / 1024 = 1023, the loop doesn't run, and 1023.999… is printed as1024.0 kB. The same happens below every larger unit (1<<30 - 1→1024.0 MB). These strings appear in the send and receive messages and in the store listing.When the rounded value is
1024.0, it now moves up one unit, so those sizes print as1.0 MBand1.0 GB. Other values are unchanged.Extended
TestByteCountDecimalwith1024*1024-1,1024*1024*1024-1, and1023*1024(which must stay1023.0 kB).I ran CI on my fork:
main):TestByteCountDecimalfails withexpected: "1.0 MB",actual: "1024.0 kB". https://github.com/ChandraChaan/croc/actions/runs/41421568300Security portability regressions (macos-15) was cancelled after 15 to 19 minutes on my fork both with and without the fix (it takes about a minute here), so I couldn't get a result for it.