This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository terminology.

View the commit online.

commit 0a79d15bbee8c495732fc41888305a9eb042b46a
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 20 12:35:42 2026 -0600

    backlog: parenthesize the arguments of BACKLOG_ROW_GET()
    
    The macro read the ring position of whatever ty was in scope instead of
    the pty it was given, and did not parenthesize its arguments: it only
    worked when called with a variable named ty and a plain row number.
    Callers so far pass exactly that, so nothing changes for them; any
    other _expression_ would read the wrong pty or the wrong row.
---
 src/bin/backlog.h    |  2 +-
 src/bin/termpty.c    | 28 ++++++++++++++++++++++++++++
 src/bin/tytest.c     |  1 +
 src/bin/unit_tests.h |  1 +
 4 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/bin/backlog.h b/src/bin/backlog.h
index da09764b..ddaca487 100644
--- a/src/bin/backlog.h
+++ b/src/bin/backlog.h
@@ -22,6 +22,6 @@ int64_t
 termpty_backlog_memory_get(void);
 
 #define BACKLOG_ROW_GET(Ty, Y) \
-   (&Ty->back[(Ty->backsize - 1 + ty->backpos - Y) % Ty->backsize])
+   (&(Ty)->back[((Ty)->backsize - 1 + (Ty)->backpos - (Y)) % (Ty)->backsize])
 
 #endif
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 2a966b67..19ddd431 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -4981,4 +4981,32 @@ tytest_termpty_free_backlog_block(void)
 }
 #endif
 
+#if defined(BINARY_TYTEST)
+/* BACKLOG_ROW_GET() reads the ring of the pty it is given, whatever the
+ * name of that pty and the shape of the row _expression_. */
+int
+tytest_backlog_row_get_args(void)
+{
+   Termsave rows[4];
+   Termpty main_pty, other;
+   Termpty *ty = &main_pty;
+   Termpty *ptys[1] = { &other };
+   int y = 1;
+
+   memset(&main_pty, 0, sizeof(main_pty));
+   memset(&other, 0, sizeof(other));
+   main_pty.back = rows;
+   main_pty.backsize = 4;
+   main_pty.backpos = 1;
+   other.back = rows;
+   other.backsize = 4;
+   other.backpos = 3;
+
+   assert(BACKLOG_ROW_GET(ty, y + 1) == &rows[2]);
+   assert(BACKLOG_ROW_GET(ptys[0], 1) == &rows[1]);
+   assert(BACKLOG_ROW_GET(ptys[0], y + 1) == &rows[0]);
+   return 0;
+}
+#endif
+
 #endif /* BINARY_TYFUZZ || BINARY_TYTEST */
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index 640daad7..0590a77e 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -83,6 +83,7 @@ static struct {
        { "resize_screen2_link_refs", tytest_resize_screen2_link_refs},
        { "backlog_block_refs", tytest_backlog_block_refs},
        { "termpty_free_backlog_block", tytest_termpty_free_backlog_block},
+       { "backlog_row_get_args", tytest_backlog_row_get_args},
        { "percent_decode", tytest_percent_decode},
        { "sgr_58_no_leak", tytest_sgr_58_no_leak},
        { "xmodkeys_set", tytest_xmodkeys_set},
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index 4d8fae40..7c5cf6db 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -56,6 +56,7 @@ int tytest_resize_screen_block_refs(void);
 int tytest_resize_screen2_link_refs(void);
 int tytest_backlog_block_refs(void);
 int tytest_termpty_free_backlog_block(void);
+int tytest_backlog_row_get_args(void);
 int tytest_percent_decode(void);
 int tytest_sgr_58_no_leak(void);
 int tytest_xmodkeys_set(void);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to