gbranden pushed a commit to branch master
in repository groff.

commit 402529b1da7abaf5611a89d5eb834f62a4cac8ea
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Mar 20 17:15:34 2026 -0500

    src/roff/troff/input.cpp: Add assertion.
    
    ...to `chop` request handler.
    
    * src/roff/troff/input.cpp (chop_macro): Add assert(3)ion to verify an
      invariant in the logic.  Instrumenting this test during a full groff
      build reveals that it's reached 670 times.
    
    Also improve code annotations.
---
 ChangeLog                | 6 ++++++
 src/roff/troff/input.cpp | 7 +++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 923648745..c0f52d2a7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2026-03-20  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/input.cpp (chop_macro): Add assert(3)ion to
+       verify an invariant in the logic.  Instrumenting this test
+       during a full groff build reveals that it's reached 670 times.
+
 2026-03-20  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/input.cpp (chop_macro): Boolify and rename
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 0391a7d16..7c440a839 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -5697,14 +5697,15 @@ void chop_macro()
     macro *m = p->to_macro();
     if (0 /* nullptr */ == m)
       error("cannot chop request '%1'", s.contents());
+    // TODO: If it's empty, do nothing, quietly?
     else if (m->is_empty())
       error("cannot chop empty %1 '%2'",
            (m->is_diversion() ? "diversion" : "macro or string"),
            s.contents());
     else {
-      // We have to check for additional save/restore pairs which could
-      // be there due to empty am1 requests.
       bool contains_mode_tokens = false;
+      // We have to check for save/restore pairs which could
+      // be present due to as1, ds1, de1, am1 requests.
       for (;;) {
        if (m->get(m->len - 1) != POP_GROFFCOMP_MODE)
          break;
@@ -5718,6 +5719,8 @@ void chop_macro()
        if (m->len == 0)
          break;
       }
+      assert(m->len != 0);
+      // TODO: If it's empty, do nothing, quietly?
       if (m->len == 0)
        error("cannot chop empty object '%1'", s.contents());
       else {

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

Reply via email to