gbranden pushed a commit to branch master
in repository groff.

commit 12fdfa28933c6b1e6ff03576d646c41693bef3a0
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sat Aug 30 05:03:56 2025 -0500

    src/roff/troff/node.cpp: Trivially refactor.
    
    `unsigned char` is a _numeric_ type, not a character type (properly
    considered).  Compare values of this type to unsigned numeric literals,
    not to character literals that are to be used with `char`, which is of
    undefined signedness.  Reorder equality comparisons to avoid inadvertent
    lvalue assignment.
    
    * src/roff/troff/node.cpp (troff_output_file::put_char_width)
      (troff_output_file::put_char, glyph_node::get_hyphenation_type)
      (node::asciify, composite_node::dump_properties, make_glyph_node): Do
      it.
    
      (charinfo_node::dump_properties): Perform explicit comparison to
      unsigned numeric literal instead of letting its value pun down to a
      Boolean.
    
    (It might be worth pointing out that `unsigned char` _is_ GNU troff's
    internal data type for representing character codes.  It is, therefore,
    the type we'll want to migrate to `int32_t` for graceful internal
    handling of the Unicode character set.  See Savannah #40720.)
---
 ChangeLog               | 15 +++++++++++++++
 src/roff/troff/node.cpp | 18 ++++++++++--------
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index af0b0183e..89e071e62 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2025-08-30  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/node.cpp: Trivially refactor.  `unsigned char`
+       is a _numeric_ type, not a character type (properly considered).
+       Compare values of this type to unsigned numeric literals, not to
+       character literals that are to be used with `char`, which is of
+       undefined signedness.  Reorder equality comparisons to avoid
+       inadvertent lvalue assignment.
+       (troff_output_file::put_char_width, troff_output_file::put_char)
+       (glyph_node::get_hyphenation_type, node::asciify)
+       (composite_node::dump_properties, make_glyph_node): Do it.
+       (charinfo_node::dump_properties): Perform explicit comparison to
+       unsigned numeric literal instead of letting its value pun down
+       to a Boolean.
+
 2025-08-30  G. Branden Robinson <[email protected]>
 
        [troff]: Make `-c` option neuter the `color` request.
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 952d5ba85..7c7821caf 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -1112,7 +1112,7 @@ void troff_output_file::put_char_width(charinfo *ci, 
tfont *tf,
   }
   set_font(tf);
   unsigned char c = ci->get_ascii_code();
-  if (c == '\0') {
+  if (0U == c) {
     stroke_color(gcol);
     fill_color(fcol);
     flush_tbuf();
@@ -1190,7 +1190,7 @@ void troff_output_file::put_char(charinfo *ci, tfont *tf,
     return;
   set_font(tf);
   unsigned char c = ci->get_ascii_code();
-  if (c == '\0') {
+  if (0U == c) {
     stroke_color(gcol);
     fill_color(fcol);
     flush_tbuf();
@@ -1954,7 +1954,7 @@ void charinfo_node::dump_properties()
   // GNU troff multiplexes the distinction of ordinary vs. special
   // characters though the special character code zero.
   unsigned char c = ci->get_ascii_code();
-  if (c) {
+  if (c != 0U) {
     fputs(", \"character\": ", stderr);
     // It's not a `string` or `symbol` we can `.json_dump()`, so we have
     // to write the quotation marks ourselves.
@@ -2293,7 +2293,7 @@ hyphenation_type glyph_node::get_hyphenation_type()
 void glyph_node::ascii_print(ascii_output_file *ascii)
 {
   unsigned char c = ci->get_ascii_code();
-  if (c != '\0')
+  if (c != 0U)
     ascii->outc(c);
   else
     ascii->outs(ci->nm.contents());
@@ -3888,9 +3888,10 @@ void node::asciify(macro *m)
 void glyph_node::asciify(macro *m)
 {
   unsigned char c = ci->get_asciify_code();
-  if (c == '\0')
+  if (0U == c)
     c = ci->get_ascii_code();
-  if (c != '\0') {
+  // XXX: What if it's a Unicode special character?
+  if (c != 0U) {
     m->append(c);
     delete this;
   }
@@ -4743,6 +4744,7 @@ void composite_node::asciify(macro *m)
   unsigned char c = ci->get_asciify_code();
   if (0U == c)
     c = ci->get_ascii_code();
+  // XXX: What if it's a Unicode special character?
   if (c != 0U) {
     m->append(c);
     delete this;
@@ -5372,7 +5374,7 @@ void composite_node::dump_properties()
   // GNU troff multiplexes the distinction of ordinary vs. special
   // characters though the special character code zero.
   unsigned char c = ci->get_ascii_code();
-  if (c) {
+  if (c != 0U) {
     fputs(", \"character\": ", stderr);
     // It's not a `string` or `symbol` we can `.json_dump()`, so we have
     // to write the quotation marks ourselves.
@@ -5484,7 +5486,7 @@ static node *make_glyph_node(charinfo *s, environment 
*env,
     if (!found) {
       if (want_warnings && s->first_time_not_found()) {
        unsigned char input_code = s->get_ascii_code();
-       if (input_code != 0) {
+       if (input_code != 0U) {
          if (csgraph(input_code))
            warning(WARN_CHAR, "character '%1' not defined",
                    input_code);

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

Reply via email to