fmt: value of minlength should not be negative#6359
Merged
BenWiederhake merged 2 commits intouutils:mainfrom May 5, 2024
Merged
fmt: value of minlength should not be negative#6359BenWiederhake merged 2 commits intouutils:mainfrom
BenWiederhake merged 2 commits intouutils:mainfrom
Conversation
Contributor
|
Can you please add a test so we don't regress in the future? |
9d44d0e to
771f695
Compare
Contributor
Author
Done |
cakebaker
reviewed
May 5, 2024
cakebaker
reviewed
May 5, 2024
src/uu/fmt/src/linebreak.rs
Outdated
| let minlength = if args.opts.goal >= stretch { | ||
| args.opts.goal - stretch | ||
| } else { | ||
| DEFAULT_GOAL_TO_WIDTH_RATIO |
Contributor
There was a problem hiding this comment.
I think this is incorrect because DEFAULT_GOAL_TO_WIDTH_RATIO represents a ratio, 93% in this case, and not an absolute value.
Contributor
Author
There was a problem hiding this comment.
I dont know what should be value of -g when minlength is negetive
Collaborator
There was a problem hiding this comment.
How about using 1? The old code seems to use stretch as a guess for how much wiggle-room there is. And if minlength has to be at least 1 anyway, well, then just use 1 as the minimum value.
// Would like to write (args.opts.goal - stretch).max(1), but that can underflow the unsigned integer:
let minlength = args.opts.goal.max(stretch + 1) - stretch;
Contributor
Author
There was a problem hiding this comment.
Yes sounds reasonable
e29369c to
c4029c2
Compare
|
GNU testsuite comparison: |
c4029c2 to
abade2d
Compare
abade2d to
82710c1
Compare
Collaborator
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.
closes #6354