gbranden pushed a commit to branch master
in repository groff.

commit e9d12a8b1660873579c18fd2696686ad41e938bb
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sat Jul 4 19:54:22 2026 -0500

    src/roff/groff/groff.cpp: Fix code style nits.
    
    * src/roff/groff/groff.cpp (possible_command::build_argv): Explicitly
      compare variable of pointer type to ISO C++98 null pointer literal,
      instead of punning it down to a Boolean.  Convert type of local
      variables `len`, `argc` and (loop locals) `i` from `int` to `size_t`,
      since they're used as or compared to array indices.  Lift computation
      of `argc + 1` into a new `const` `size_t` variable `argv_len`, for the
      same reason and to prepare for a forthcoming change.
---
 ChangeLog                | 11 +++++++++++
 src/roff/groff/groff.cpp | 13 +++++++------
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index acdb3683a..472562313 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2026-07-04  G. Branden Robinson <[email protected]>
+
+       * src/roff/groff/groff.cpp (possible_command::build_argv): Fix
+       code style nits.  Explicitly compare variable of pointer type to
+       ISO C++98 null pointer literal, instead of punning it down to a
+       Boolean.  Convert type of local variables `len`, `argc` and
+       {loop locals} `i` from `int` to `size_t`, since they're used as
+       or compared to array indices.  Lift computation of `argc + 1`
+       into a new `const` `size_t` variable `argv_len`, for the same
+       reason and to prepare for a forthcoming change.
+
 2026-07-04  G. Branden Robinson <[email protected]>
 
        * src/preproc/grn/main.cpp (operand): Exit with status 2, not 8,
diff --git a/src/roff/groff/groff.cpp b/src/roff/groff/groff.cpp
index 10129306c..04bfeb665 100644
--- a/src/roff/groff/groff.cpp
+++ b/src/roff/groff/groff.cpp
@@ -724,22 +724,23 @@ void possible_command::insert_args(string s)
 
 void possible_command::build_argv()
 {
-  if (argv)
+  if (argv != 0 /* nullptr */)
     return;
   // Count the number of arguments.
-  int len = args.length();
-  int argc = 1;
+  size_t len = args.length();
+  size_t argc = 1;
   char *p = 0 /* nullptr */;
   if (len > 0) {
     p = &args[0];
-    for (int i = 0; i < len; i++)
+    for (size_t i = 0; i < len; i++)
       if (p[i] == '\0')
        argc++;
   }
   // Build an argument vector.
-  argv = new char *[argc + 1];
+  const size_t argv_len = argc + 1;
+  argv = new char *[argv_len];
   argv[0] = name;
-  for (int i = 1; i < argc; i++) {
+  for (size_t i = 1; i < argc; i++) {
     argv[i] = p;
     p = strchr(p, '\0') + 1;
   }

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

Reply via email to