gbranden pushed a commit to branch master
in repository groff.

commit 96aaf680437ce4809a5f18eb01fa4ef0e5b56a94
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Mar 20 21:23:25 2026 -0500

    src/roff/troff/input.cpp: Slightly refactor.
    
    * src/roff/troff/input.cpp (abort_request): Avail ourselves of the
      `has_arg()` function; don't mess with any of the input character
      processing rigmarole if there is no such input to process.  Also flush
      the standard error stream only if we have written to it.  If someone
      feels that this should happen anyway "just in case" some other part of
      GNU troff neglects to do so, then an even better place for that
      insurance policy is `write_any_trailer_and_exit()`--it lies on _all_
      controlled paths out of the program.
---
 ChangeLog                | 12 ++++++++++++
 src/roff/troff/input.cpp | 34 ++++++++++++++++++----------------
 2 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d1d22359c..919b9412c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,18 @@
        not the case; if the operation proceeds, it edits the string/
        macro/diversion's contents in place.
 
+2026-03-20  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/input.cpp (abort_request): Slightly refactor.
+       Avail ourselves of the `has_arg()` function; don't mess with any
+       of the input character processing rigmarole if there is no such
+       input to process.  Also flush the standard error stream only if
+       we have written to it.  If someone feels that this should
+       happen anyway "just in case" some other part of GNU troff
+       neglects to do so, then an even better place for that insurance
+       policy is `write_any_trailer_and_exit()`--it lies on _all_
+       controlled paths out of the program.
+
 2026-03-20  G. Branden Robinson <[email protected]>
 
        * src/roff/groff/tests/ab-request-works.sh: Conform better to
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 55de22544..0ac68953c 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -9359,23 +9359,25 @@ const char *readonly_mask_register::get_string()
 
 void abort_request()
 {
-  int c;
-  if (tok.is_eof())
-    c = EOF;
-  else if (tok.is_newline())
-    c = '\n';
-  else {
-    while ((c = read_char_in_copy_mode(0 /* nullptr */)) == ' ')
-      ;
-  }
-  if ((c != '\n') && (c != EOF)) {
-    for (;
-        (c != '\n') && (c != EOF);
-        (c = read_char_in_copy_mode(0 /* nullptr */)))
-      fputs(encode_for_stream_output(c), stderr);
-    fputc('\n', stderr);
+  if (has_arg(true /* peek */)) {
+    int c;
+    if (tok.is_eof())
+      c = EOF;
+    else if (tok.is_newline())
+      c = '\n';
+    else {
+      while ((c = read_char_in_copy_mode(0 /* nullptr */)) == ' ')
+       ;
+    }
+    if ((c != '\n') && (c != EOF)) {
+      for (;
+          (c != '\n') && (c != EOF);
+          (c = read_char_in_copy_mode(0 /* nullptr */)))
+       fputs(encode_for_stream_output(c), stderr);
+      fputc('\n', stderr);
+      fflush(stderr);
+    }
   }
-  fflush(stderr);
   write_any_trailer_and_exit(EXIT_FAILURE);
 }
 

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

Reply via email to