Skip to content

pr: stream -o/--indent offset to avoid abort on large values#12994

Open
TheAdamWarlock wants to merge 1 commit into
uutils:mainfrom
TheAdamWarlock:fix/pr-offset-abort
Open

pr: stream -o/--indent offset to avoid abort on large values#12994
TheAdamWarlock wants to merge 1 commit into
uutils:mainfrom
TheAdamWarlock:fix/pr-offset-abort

Conversation

@TheAdamWarlock

Copy link
Copy Markdown
Contributor

Fixes #12978.

pr -o N (--indent) aborted on large offsets that fit in i32 (e.g. -o 999999999) because the indent was built as " ".repeat(n), allocating an N-byte string up front that fails under limited memory. The change stores the offset as a count and streams the spaces in 256-byte chunks at print time, so peak memory is constant and output is unchanged. Adds a regression test that runs pr with a large offset under a small memory cap and checks it exits cleanly.

Store the indent as a count and stream the spaces at print time instead of allocating an N-byte string up front. Added regression test as well.
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/retry (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/symlink (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/rm/many-dir-entries-vs-OOM is now passing!

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.

bug(pr): ulimit -v 15850; ./pr -o 999999999 panics

1 participant