Skip to content

fmt: never let a line run past WIDTH when no break fits - #16191

Merged
cakebaker merged 1 commit into
uutils:mainfrom
emirmrkaljevic:fmt-width-overflow
Nov 5, 2026
Merged

cakebaker merged 1 commit into
uutils:mainfrom
emirmrkaljevic:fmt-width-overflow

Conversation

@emirmrkaljevic

Copy link
Copy Markdown
Contributor

Fixes #16190

When no active break can take the next word, restart_active_breaks chose between breaking early and breaking late by comparing how short or how long the line would get. Breaking late always overflows WIDTH there, so it now always breaks before the word (unless the line is fresh, where the word has to stay). This matches GNU fmt, where WIDTH is a hard maximum.

$ printf '    at a narrow width x y\n' | fmt -w 20
    at a narrow
    width x y

Added test_fmt_width_is_a_hard_maximum. Found with behave.

@cakebaker
cakebaker merged commit d3b9806 into uutils:main Nov 5, 2026
137 of 138 checks passed
@cakebaker

Copy link
Copy Markdown
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fmt: output lines can be longer than WIDTH

2 participants