gbranden pushed a commit to branch master
in repository groff.

commit 7c025fb84bfa045af24231ece3940865e125357f
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Nov 30 03:33:40 2025 -0600

    [troff]: Fix Savannah #67746 (`\s` delim diag).
    
    * src/roff/troff/input.cpp (read_size): Clarify diagnostic when an `\s`
      escape sequence that is bracketed or delimited (a GNU extension)
      contains an invalid numeric expression.  Describe what we were
      expecting and what we got instead.
    
    Fixes <https://savannah.gnu.org/bugs/?67746>.  Problem observable since
    groff 1.22.3 and appears to date back to groff's birth.
    
    Illustration:
    $ printf '\\s"1a"\n' | ~/groff-1.22.3/bin/groff -a
    <standard input>:1: missing closing delimiter
    <beginning of page>
    "
    $ printf '\\s"1a"\n' | ~/groff-1.22.4/bin/groff -a
    troff: <standard input>:1: missing closing delimiter
    <beginning of page>
    "
    $ printf '\\s"1a"\n' | ~/groff-1.23.0/bin/groff -a
    troff:<standard input>:1: error: missing closing delimiter in type size 
escape sequence
    <beginning of page>
    "
    $ printf '\\s"1a"\n' | ./build/test-groff -a
    troff:<standard input>:1: error: closing delimiter does not match; expected 
character '"', got character 'a'
    <beginning of page>
    "
---
 ChangeLog                | 11 +++++++++++
 src/roff/troff/input.cpp | 12 ++++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index da2bb3645..1c8711e1d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2025-11-30  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/input.cpp (read_size): Clarify diagnostic when
+       an `\s` escape sequence that is bracketed or delimited (a GNU
+       extension) contains an invalid numeric expression.  Describe
+       what we were expecting and what we got instead.
+
+       Fixes <https://savannah.gnu.org/bugs/?67746>.  Problem
+       observable since groff 1.22.3 and appears to date back to
+       groff's birth.
+
 2025-11-26  G. Branden Robinson <[email protected]>
 
        [troff]: Perform more careful comparisons of the `unsigned char`
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 965f20851..6a0a86315 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -6109,8 +6109,16 @@ static bool read_size(int *x) // \s
     if (!((s == int('[')) && (t == int(']'))) && (start != tok)) {
       if (s == int('['))
        error("missing ']' in type size escape sequence");
-      else
-       error("missing closing delimiter in type size escape sequence");
+      else {
+       // token::description() writes to static, class-wide storage, so
+       // we must allocate a copy of it before issuing the next
+       // diagnostic.
+       char *delimdesc = strdup(start.description());
+       if (s != t)
+         error("closing delimiter does not match; expected %1, got %2",
+               delimdesc, tok.description());
+       free(delimdesc);
+      }
       return false;
     }
   }

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

Reply via email to