gbranden pushed a commit to branch master
in repository groff.

commit 873873ce3c293fa06bbd4257edc3ac4b361cf32e
Author: G. Branden Robinson <g.branden.robin...@gmail.com>
AuthorDate: Thu Jul 10 19:01:56 2025 -0500

    [troff]: Slightly refactor escape arg reading.
    
    * src/roff/troff/input.cpp (read_long_escape_parameters): Slightly
      refactor.  Test for an empty argument (or argument sequence) earlier,
      before worrying about whether the input buffer just populated is still
      the stack-allocated one or was relocated to the heap.  This is to
      facilitate a simplification of input buffer management.
---
 ChangeLog                |  9 +++++++++
 src/roff/troff/input.cpp | 14 +++++++-------
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7c3179a14..e97d3d0e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2025-07-10  G. Branden Robinson <g.branden.robin...@gmail.com>
+
+       * src/roff/troff/input.cpp (read_long_escape_parameters):
+       Slightly refactor.  Test for an empty argument (or argument
+       sequence) earlier, before worrying about whether the input
+       buffer just populated is still the stack-allocated one or was
+       relocated to the heap.  This is to facilitate a simplification
+       of input buffer management.
+
 2025-07-10  G. Branden Robinson <g.branden.robin...@gmail.com>
 
        * src/roff/troff/input.cpp (read_rest_of_line_as_argument):
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 61597922d..d2a72ffa1 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -1034,16 +1034,16 @@ static symbol read_long_escape_parameters(read_mode 
mode)
     buf[i++] = c;
   }
   buf[i] = 0;
+  if (i == 0) {
+    if (mode != ALLOW_EMPTY)
+      // XXX: `.device \[]` passes through as-is but `\X \[]` doesn't,
+      // landing here.  Implement almost-but-not-quite-copy-mode?
+      copy_mode_error("empty escape sequence argument in copy mode");
+    return EMPTY_SYMBOL;
+  }
   if (c == ' ')
     have_multiple_params = true;
   if (buf == abuf) {
-    if (i == 0) {
-      if (mode != ALLOW_EMPTY)
-       // XXX: `.device \[]` passes through as-is but `\X \[]` doesn't,
-       // landing here.  Implement almost-but-not-quite-copy-mode?
-       copy_mode_error("empty escape sequence argument in copy mode");
-      return EMPTY_SYMBOL;
-    }
     return symbol(abuf);
   }
   else {

_______________________________________________
groff-commit mailing list
groff-commit@gnu.org
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to