gbranden pushed a commit to branch master
in repository groff.

commit 88615ff8696bfca5ac07655b1308a027635e06aa
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Sep 1 20:30:39 2024 -0500

    [troff]: Fix bug in `\X` Unicode generation.
    
    * src/roff/troff/input.cpp (encode_special_character_for_device_output):
      Fix off-by-one error in C-style string handling, which led to
      truncation of composite Unicode special character sequence in some
      cases.  Fixes problem introduced by me in commit c8332c5c1a, 25
      August.  Thanks to Deri James for the report.
---
 ChangeLog                | 9 +++++++++
 src/roff/troff/input.cpp | 7 ++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e6b6f18e1..73100c5cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-09-01  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/input.cpp
+       (encode_special_character_for_device_output): Fix off-by-one
+       error in C-style string handling, which led to truncation of
+       composite Unicode special character sequence in some cases.
+       Fixes problem introduced by me in commit c8332c5c1a, 25 August.
+       Thanks to Deri James for the report.
+
 2024-08-30  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/env.cpp (environment::choose_breakpoint): Fix
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 4501f8a65..aeab5edfe 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -5751,7 +5751,8 @@ static void 
encode_special_character_for_device_output(macro *mac)
     }
     else {
       char errbuf[ERRBUFSZ];
-      char character[UNIBUFSZ + 1 /* '\0' */];
+      const size_t unibufsz = UNIBUFSZ + 1 /* '\0' */;
+      char character[unibufsz];
       (void) memset(errbuf, '\0', ERRBUFSZ);
       (void) memset(character, '\0', UNIBUFSZ);
       // If looks like something other than an attempt at a Unicode
@@ -5761,7 +5762,7 @@ static void 
encode_special_character_for_device_output(macro *mac)
       if ((strlen(sc) < 3) || (sc[0] != 'u')) {
        const char *un = glyph_name_to_unicode(sc);
        if (un != 0 /* nullptr */)
-         strncpy(character, un, UNIBUFSZ);
+         strncpy(character, un, unibufsz);
        else {
          warning(WARN_CHAR, "special character '%1' is not encodable"
               " in device-independent output", sc);
@@ -5775,7 +5776,7 @@ static void 
encode_special_character_for_device_output(macro *mac)
               " in device-independent output: %2", sc, errbuf);
          return;
        }
-       strncpy(character, un, UNIBUFSZ);
+       strncpy(character, un, unibufsz);
       }
       mac->append_str("\\[u");
       mac->append_str(character);

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

Reply via email to