gbranden pushed a commit to branch master
in repository groff.

commit a9342dcb9ac41ce6ae2794c40401cb2b31413998
Author: G. Branden Robinson <[email protected]>
AuthorDate: Mon Nov 23 22:01:17 2026 -0600

    src/devices/grotty/tty.cpp: Fix overflow check.
    
    * src/devices/grotty/tty.cpp (tty_printer::add_char): Stop provoking UB
      while trying to prevent UB.  Rewrite test for signed integer overflow.
      See CERT C Rule INT32-C.  Clarify fatal diagnostic when integer
      overflow would occur.
    
    Continues commit 112ec43851, 20 November, fixing Savannah #68942.
---
 ChangeLog                  | 10 ++++++++++
 src/devices/grotty/tty.cpp |  6 +++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7d6ef5f78..26a50cbcb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2026-11-23  G. Branden Robinson <[email protected]>
+
+       * src/devices/grotty/tty.cpp (tty_printer::add_char): Stop
+       provoking UB while trying to prevent UB.  Rewrite test for
+       signed integer overflow.  See CERT C Rule INT32-C.  Clarify
+       fatal diagnostic when integer overflow would occur.
+
+       Continues commit 112ec43851, 20 November, fixing Savannah
+       #68942.
+
 2026-11-23  G. Branden Robinson <[email protected]>
 
        * src/devices/grotty/tty.cpp (tty_printer::add_char): Restore
diff --git a/src/devices/grotty/tty.cpp b/src/devices/grotty/tty.cpp
index b69e0cf12..135d27879 100644
--- a/src/devices/grotty/tty.cpp
+++ b/src/devices/grotty/tty.cpp
@@ -430,10 +430,10 @@ void tty_printer::add_char(output_character c, int w,
     // #68145.
     tty_glyph **old_lines = lines;
     int new_nlines = nlines;
-    while ((vpos > new_nlines) && (new_nlines > 0))
+    while ((vpos > new_nlines) && (new_nlines < (INT_MAX / 2)))
       new_nlines *= 2;
-    if (new_nlines < 0)
-      fatal("vertical motion to line %1 is too large", vpos);
+    if (vpos > new_nlines)
+      fatal("requested vertical motion to line %1 is too large", vpos);
     lines = 0 /* nullptr */;
     try {
       lines = new tty_glyph *[new_nlines];

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to