-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fmt: value of minlength should not be negative #6359
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont know what should be value of -g when minlength is negetive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes sounds reasonable
e29369c
to
c4029c2
Compare
GNU testsuite comparison:
|
c4029c2
to
abade2d
Compare
abade2d
to
82710c1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
closes #6354