This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch tymux-10-quiet-head
in repository terminology.
View the commit online.
commit 9da224cf0e540f9607e9d17815ad01bdd4d27e83
Author: Boris Faure <[email protected]>
AuthorDate: Wed Nov 4 22:28:48 2026 +0000
backlog: grow a wrapped backlog row geometrically
Each screen row a long wrapped line moved into the backlog
reallocated the row to its exact new size; an allocator that moves the
block copies the whole line each time: under ASAN, a 1 MiB line took
46 s to scroll through, and now takes 0.12 s. Found by AFL.
A wrapped row may now hold up to twice the cells it uses; the backlog
memory accounting already counts the allocation, not the content.
---
src/bin/backlog.c | 9 ++++++---
tests/backlog-long-line.sh | 13 +++++++++++++
tests/tests.results | 1 +
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/src/bin/backlog.c b/src/bin/backlog.c
index d247ac56..e769ee2a 100644
--- a/src/bin/backlog.c
+++ b/src/bin/backlog.c
@@ -117,12 +117,15 @@ termpty_save_expand(Termpty *ty, Termsave *ts, Termcell *cells, size_t delta)
if (need > ts->cap)
{
- newcells = realloc(ts->cells, need * sizeof(Termcell));
+ /* grown geometrically, else each wrapped row copies the line whole */
+ size_t cap = MAX(need, (size_t)ts->cap * 2);
+
+ newcells = realloc(ts->cells, cap * sizeof(Termcell));
if (!newcells)
return NULL;
_accounting_change((-1) * (int64_t)(ts->cap * sizeof(Termcell)));
- _accounting_change(need * sizeof(Termcell));
- ts->cap = need;
+ _accounting_change(cap * sizeof(Termcell));
+ ts->cap = cap;
ts->cells = newcells;
}
else
diff --git a/tests/backlog-long-line.sh b/tests/backlog-long-line.sh
new file mode 100755
index 00000000..f75013ec
--- /dev/null
+++ b/tests/backlog-long-line.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+# shellcheck source=tests/utils.sh
+. "$(dirname "$0")/utils.sh"
+
+# clear screen
+printf '\033[2J'
+
+# move to 0; 0
+printf '\033[0;0H'
+
+# a 1 MiB line, wrapped over and over into a single backlog row
+head -c 1048576 /dev/zero | tr '\0' 'A'
+printf '\r\nB'
diff --git a/tests/tests.results b/tests/tests.results
index 101ded35..26526aeb 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -205,3 +205,4 @@ xtgettcap.sh 300a0521bca0f2bf50bc00161f8fc195
crash_cup_col_over_margin.sh 400a5215c6e74782cbab076e2a81fff7
dcs-cancel.sh 5802db97bcbf6f2ab0d8e49723fcfea8
dcs-long.sh 56028fb44070f1bf64f323f751f0d79a
+backlog-long-line.sh f4423fa1c7069b9bf8a62045cc97dda3
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.