fmt: value of minlength should not be negative#6359
fmt: value of minlength should not be negative#6359BenWiederhake merged 2 commits intouutils:mainfrom
Conversation
|
Can you please add a test so we don't regress in the future? |
9d44d0e to
771f695
Compare
Done |
src/uu/fmt/src/linebreak.rs
Outdated
| let minlength = if args.opts.goal >= stretch { | ||
| args.opts.goal - stretch | ||
| } else { | ||
| DEFAULT_GOAL_TO_WIDTH_RATIO |
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.
There was a problem hiding this comment.
I dont know what should be value of -g when minlength is negetive
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;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
closes #6354