gbranden pushed a commit to branch master
in repository groff.

commit 4ce8551e96912e1c06fa68c01232d1e88a72a2b1
Author: G. Branden Robinson <[email protected]>
AuthorDate: Tue Dec 23 19:49:02 2025 -0600

    [troff]: Improve diagnostic messages.
    
    * src/roff/troff/input.cpp (token::description): Improve diagnostic when
      describing a nonexistent special character or class by reporting its
      identifier, at least up to the point where the size of our buffer
      truncates it.  (How do you get a "nonexistent special character or
      class" that nevertheless has an identifier?  It's part of the input
      syntax.  What you do is attempt to interpolate a special character (or
      class--an invalid operation anyway, but stay with me) in a context
      where character interpolation makes no sense, as in a numeric
      expression.
    
    Before:
    $ printf '.pl \\(nlu\n' | ~/groff-HEAD/bin/groff
    troff:<standard input>:1: error: ignoring invalid numeric expression 
starting with nonexistent special character or class
    
    After:
    $ printf '.pl \\(nlu\n' | ./build/test-groff
    troff:<standard input>:1: error: ignoring invalid numeric expression 
starting with nonexistent special character or class 'nl'
---
 ChangeLog                | 12 ++++++++++++
 src/roff/troff/input.cpp | 10 +++++-----
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 861844f5d..67581ab3a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2025-12-23  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/input.cpp (token::description): Improve
+       diagnostic when describing a nonexistent special character or
+       class by reporting its identifier, at least up to the point
+       where the size of our buffer truncates it.  (How do you get a
+       "nonexistent special character or class" that nevertheless has
+       an identifier?  It's part of the input syntax.  What you do is
+       attempt to interpolate a special character (or class--an invalid
+       operation anyway, but stay with me) in a context where character
+       interpolation makes no sense, as in a numeric expression.
+
 2025-12-21  G. Branden Robinson <[email protected]>
 
        * src/preproc/preconv/preconv.cpp (do_file): Say "non-portable"
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 597f055da..5000e8bf8 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -3057,16 +3057,16 @@ const char *token::description()
       // closing quotation mark.)
       static const char special_character[] = "special character";
       static const char character_class[] = "character class";
+      static const char nonexistent[] = "nonexistent special character"
+                                       " or class";
       const char *ctype = special_character;
       charinfo *ci = get_charinfo(false /* required */,
                                  true /* suppress creation */);
-      if (0 /* nullptr */ == ci) {
-       // We can get here via, e.g., `.pl \(nlu` (likely a typo).
-       return "nonexistent special character or class";
-      }
+      if (0 /* nullptr */ == ci)
+       ctype = nonexistent;
       else if (ci->is_class())
        ctype = character_class;
-      (void) snprintf(buf, maxstr, "%s %c%s%c", ctype, qc, sc, qc);
+      (void) snprintf(buf, bufsz, "%s %c%s%c", ctype, qc, sc, qc);
       return buf;
     }
   case TOKEN_SPREAD:

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

Reply via email to