gbranden pushed a commit to branch master
in repository groff.

commit 549772eea107107c0760bc5255b702ca4ed63407
Author: G. Branden Robinson <[email protected]>
AuthorDate: Mon Jul 13 10:08:16 2026 -0500

    [troff]: Avoid undefined behavior if `NDEBUG`.
    
    * src/roff/troff/input.cpp (charinfo::set_number)
      (charinfo::get_number): Make `NDEBUG` execution traces safer: clamp
      negative character indices to zero, avoiding undefined formatter
      behavior.
---
 ChangeLog                | 7 +++++++
 src/roff/troff/input.cpp | 4 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 389aa2d45..4186dcecb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2026-07-13  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/input.cpp (charinfo::set_number)
+       (charinfo::get_number): Make `NDEBUG` execution traces safer:
+       clamp negative character indices to zero, avoiding undefined
+       formatter behavior.
+
 2026-07-13  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/input.cpp (charinfo::set_number): Trivially
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 3d444662e..c4b65e98f 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -11166,13 +11166,13 @@ macro *charinfo::set_macro(macro *m, char_mode cm)
 void charinfo::set_number(int idx)
 {
   assert(idx >= 0);
-  number = idx;
+  number = (idx < 0 ? 0 : idx);
 }
 
 int charinfo::get_number()
 {
   assert(number >= 0);
-  return number;
+  return (number < 0) ? 0 : number;
 }
 
 bool charinfo::contains(int c, bool already_called)

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

Reply via email to