gbranden pushed a commit to branch master
in repository groff.

commit e16c40640def888dea60aa29278597c0c81ee2ba
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu Aug 15 10:22:24 2024 -0500

    [troff]: Fix code style nits.
    
    * src/roff/troff/env.cpp (override_sizes):
    * src/roff/troff/input.cpp (pipe_source): Add parentheses to complex
      expressions.
    
    * src/roff/troff/env.cpp (add_hyphenation_exceptions): Reorder equality
      comparisons to avoid inadvertent lvalue assignment.
    
      (add_hyphenation_exceptions, hyphen_trie::insert_hyphenation): Use
      `static_cast` instead of C-style cast on dictionary values.
    
    * src/roff/troff/env.cpp (add_hyphenation_exceptions)
      (hyphen_trie::insert_hyphenation):
    * src/roff/troff/input.cpp (read_two_char_escape_parameter)
      (do_get_long_name): Assign character, not integer, literal to element
      of array of `char` type.
    
    * src/roff/troff/input.cpp (read_long_escape_parameters): Demote local
      variable `have_char` from `int` to `bool` and assign to it with
      Boolean, not integer, literals.
    
    * src/roff/troff/input.cpp (do_get_long_name): Explcitly express size of
      array element type in argument to `memcpy()`.
    
    Also annotate null pointers with `nullptr` comment to ease any future
    transition to C++11, which defines it as a keyword.
    
    Also use spaces around binary operators.
---
 ChangeLog                | 24 ++++++++++++++++++++++++
 src/roff/troff/env.cpp   | 18 +++++++++---------
 src/roff/troff/input.cpp | 38 +++++++++++++++++++-------------------
 3 files changed, 52 insertions(+), 28 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8f4b3a9db..f3a98cd1d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2024-08-15  G. Branden Robinson <[email protected]>
+
+       [troff]: Fix code style nits.
+
+       * src/roff/troff/env.cpp (override_sizes): Add parentheses to
+       complex expressions.
+       (add_hyphenation_exceptions): Reorder equality comparisons to
+       avoid inadvertent lvalue assignment.
+       (add_hyphenation_exceptions, hyphen_trie::insert_hyphenation):
+       Use `static_cast` instead of C-style cast on dictionary values.
+
+       * src/roff/troff/env.cpp (add_hyphenation_exceptions)
+       (hyphen_trie::insert_hyphenation):
+       * src/roff/troff/input.cpp (read_two_char_escape_parameter)
+       (do_get_long_name): Assign character, not integer, literal to
+       element of array of `char` type.
+
+       * src/roff/troff/input.cpp (read_long_escape_parameters): Demote
+       local variable `have_char` from `int` to `bool` and assign to it
+       with Boolean, not integer, literals.
+
+       * src/roff/troff/input.cpp (do_get_long_name): Explcitly
+       express size of array element type in argument to `memcpy()`.
+
 2024-08-14  Lukas Javorsky <[email protected]>
 
        * src/roff/troff/env.cpp (override_sizes): Zero out
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index b54df35e9..d8e51fade 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -1344,7 +1344,7 @@ void override_sizes()
     if (i + 2 > n) {
       int *old_sizes = sizes;
       sizes = new int[n * 2];
-      memcpy(sizes, old_sizes, n * sizeof(int));
+      memcpy(sizes, old_sizes, (n * sizeof(int)));
       n *= 2;
       delete[] old_sizes;
     }
@@ -3647,7 +3647,7 @@ static void add_hyphenation_exceptions()
     while (i < WORD_MAX && !tok.is_space() && !tok.is_newline()
           && !tok.is_eof()) {
       charinfo *ci = tok.get_char(true /* required */);
-      if (ci == 0) {
+      if (0 /* nullptr */ == ci) {
        skip_line();
        return;
       }
@@ -3658,18 +3658,18 @@ static void add_hyphenation_exceptions()
       }
       else {
        unsigned char c = ci->get_hyphenation_code();
-       if (c == 0)
+       if (0 == c)
          break;
        buf[i++] = c;
       }
     }
     if (i > 0) {
       pos[npos] = 0;
-      buf[i] = 0;
+      buf[i] = '\0';
       unsigned char *tem = new unsigned char[npos + 1];
       memcpy(tem, pos, npos + 1);
-      tem = (unsigned char *)current_language->exceptions.lookup(symbol(buf),
-                                                                tem);
+      tem = static_cast<unsigned char *>
+           (current_language->exceptions.lookup(symbol(buf), tem));
       if (tem)
        delete[] tem;
     }
@@ -3825,11 +3825,11 @@ void hyphen_trie::insert_hyphenation(dictionary *ex, 
const char *pat,
   }
   if (i > 0) {
     pos[npos] = 0;
-    buf[i] = 0;
+    buf[i] = '\0';
     unsigned char *tem = new unsigned char[npos + 1];
     memcpy(tem, pos, npos + 1);
-    tem = (unsigned char *)ex->lookup(symbol(buf), tem);
-    if (tem)
+    tem = static_cast<unsigned char *>(ex->lookup(symbol(buf), tem));
+    if (0 /* nullptr */ == tem)
       delete[] tem;
   }
 }
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 44390f895..b2c5bfdcd 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -959,9 +959,9 @@ static symbol read_two_char_escape_parameter()
   if (buf[0] != '\0') {
     buf[1] = get_char_for_escape_parameter();
     if (buf[1] == '\0')
-      buf[0] = 0;
+      buf[0] = '\0';
     else
-      buf[2] = 0;
+      buf[2] = '\0';
   }
   return symbol(buf);
 }
@@ -974,7 +974,7 @@ static symbol read_long_escape_parameters(read_mode mode)
   int buf_size = ABUF_SIZE;
   int i = 0;
   char c;
-  int have_char = 0;
+  bool have_char = false;
   for (;;) {
     c = get_char_for_escape_parameter(have_char && mode == WITH_ARGS);
     if (c == 0) {
@@ -982,18 +982,18 @@ static symbol read_long_escape_parameters(read_mode mode)
        delete[] buf;
       return NULL_SYMBOL;
     }
-    have_char = 1;
+    have_char = true;
     if (mode == WITH_ARGS && c == ' ')
       break;
     if (i + 2 > buf_size) {
       if (buf == abuf) {
-       buf = new char[ABUF_SIZE*2];
+       buf = new char[ABUF_SIZE * 2];
        memcpy(buf, abuf, buf_size);
-       buf_size = ABUF_SIZE*2;
+       buf_size = ABUF_SIZE * 2;
       }
       else {
        char *old_buf = buf;
-       buf = new char[buf_size*2];
+       buf = new char[buf_size * 2];
        memcpy(buf, old_buf, buf_size);
        buf_size *= 2;
        delete[] old_buf;
@@ -2732,19 +2732,19 @@ static symbol do_get_long_name(bool required, char 
end_char)
     // If `end_char` != `\0` we normally have to append a null byte.
     if (i + 2 > buf_size) {
       if (buf == abuf) {
-       buf = new char[ABUF_SIZE*2];
-       memcpy(buf, abuf, buf_size);
-       buf_size = ABUF_SIZE*2;
+       buf = new char[ABUF_SIZE * 2];
+       memcpy(buf, abuf, (buf_size * sizeof(char)));
+       buf_size = ABUF_SIZE * 2;
       }
       else {
        char *old_buf = buf;
-       buf = new char[buf_size*2];
-       memcpy(buf, old_buf, buf_size);
+       buf = new char[buf_size * 2];
+       memcpy(buf, old_buf, (buf_size * sizeof(char)));
        buf_size *= 2;
        delete[] old_buf;
       }
     }
-    if ((buf[i] = tok.ch()) == 0 || buf[i] == end_char)
+    if ((buf[i] = tok.ch()) == '\0' || buf[i] == end_char)
       break;
     i++;
     tok.next();
@@ -5362,13 +5362,13 @@ static symbol get_delimited_name()
   for (;;) {
     if (i + 1 > buf_size) {
       if (buf == abuf) {
-       buf = new char[ABUF_SIZE*2];
+       buf = new char[ABUF_SIZE * 2];
        memcpy(buf, abuf, buf_size);
-       buf_size = ABUF_SIZE*2;
+       buf_size = ABUF_SIZE * 2;
       }
       else {
        char *old_buf = buf;
-       buf = new char[buf_size*2];
+       buf = new char[buf_size * 2];
        memcpy(buf, old_buf, buf_size);
        buf_size *= 2;
        delete[] old_buf;
@@ -6263,7 +6263,7 @@ void pipe_source()
       for (; c != '\n' && c != EOF; c = get_copy(0)) {
        const char *s = asciify(c);
        size_t slen = strlen(s);
-       if (buf_used + slen + 1> buf_size) {
+       if ((buf_used + slen + 1) > buf_size) {
          char *old_buf = buf;
          size_t old_buf_size = buf_size;
          buf_size *= 2;
@@ -7887,7 +7887,7 @@ char *read_string()
     if (!is_invalid_input_char(c)) {
       if (i + 2 > len) {
        char *tem = s;
-       s = new char[len*2];
+       s = new char[len * 2];
        memcpy(s, tem, len);
        len *= 2;
        delete[] tem;
@@ -7900,7 +7900,7 @@ char *read_string()
   tok.next();
   if (i == 0) {
     delete[] s;
-    return 0;
+    return 0 /* nullptr */;
   }
   return s;
 }

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

Reply via email to