With GNU extensions disabled, before_max_width can go negative, and
define_all_fields then loops forever trying to shrink the before field
to a width narrower than empty:
$ printf 'qux\n' | src/ptx -G -w2
[hangs]
Commit
v6.12-96-g773be9eca added a clamp for this, but placed it in
the GNU-extensions branch only. Move it after that if/else so that
both branches are covered.
* src/ptx.c (fix_output_parameters): Clamp before_max_width for both
the GNU and non-GNU cases.
* tests/ptx/ptx-overrun.sh: Add a test case.
* NEWS: Mention the bug fix.
Fixes https://bugs.gnu.org/81507
like when processing large tab stops.
[This bug was present in "the beginning".]
+ 'ptx -G' no longer hangs when the output width is smaller than twice the
+ gap size, as with 'ptx -G -w4', or when a long reference leaves that
+ little room, as with 'ptx -G -r'.
+ [This bug was present in "the beginning".]
+
'shred' no longer blocks when opening a FIFO that has no readers.
[This bug was present in "the beginning".]
right side, or one on either side. */
before_max_width -= 2 * truncation_string_length;
- if (before_max_width < 0)
- before_max_width = 0;
keyafter_max_width -= 2 * truncation_string_length;
}
else
keyafter_max_width -= 2 * truncation_string_length + 1;
}
+ if (before_max_width < 0)
+ before_max_width = 0;
+
/* Compute which characters need special output processing. Initialize
by flagging any white space character. Some systems do not consider
form feed as a space character, but we do. */
echo a > a
ptx -w1 -A "$PWD/a" >/dev/null || fail=1
+
+# Trigger an infinite loop from coreutils-9.11 and earlier.
+# This would hang with -G whenever (width >> 1) < gap size.
+printf 'qux\n' | timeout 10 ptx -G -w2 || fail=1
+
+
Exit $fail