gbranden pushed a commit to branch master
in repository groff.

commit 9f511c4b61e61b93ddde9fb6372e72e5ff53f9cf
Author: G. Branden Robinson <[email protected]>
AuthorDate: Mon Nov 16 12:14:18 2026 -0600

    [pic]: Migrate to strdup(3).
    
    * src/preproc/pic/lex.cpp
      (macro_input::macro_input)
      (interpolate_macro_with_args)
      (copy_thru_input::copy_thru_input)
      (get_thru_arg)
      (yylex):
    * src/preproc/pic/main.cpp (do_picture):
    * src/preproc/pic/object.cpp
      (output::set_args)
      (graphic_object::set_fill_color)
      (graphic_object::set_outline_color)
      (closed_object::set_fill_color):
      (polygon_object::set_fill_color):
    * src/preproc/pic/pic.ypp (do_sprintf):
    * src/preproc/pic/troff.cpp (troff_output::set_color): Migrate from
      libgroff's `strsave()` to POSIX's strdup(3).
    
    Continues the long process of fixing Savannah #66672.
---
 ChangeLog                  | 23 +++++++++++++++++++++++
 src/preproc/pic/lex.cpp    | 44 ++++++++++++++++++++++----------------------
 src/preproc/pic/main.cpp   |  7 +++----
 src/preproc/pic/object.cpp | 12 ++++++------
 src/preproc/pic/pic.ypp    |  7 +++----
 src/preproc/pic/troff.cpp  |  7 +++----
 6 files changed, 60 insertions(+), 40 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bcb91dd7b..ee20f2a6d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2026-11-16  G. Branden Robinson <[email protected]>
+
+       [pic]: Migrate to strdup(3).
+
+       * src/preproc/pic/lex.cpp
+       (macro_input::macro_input)
+       (interpolate_macro_with_args)
+       (copy_thru_input::copy_thru_input)
+       (get_thru_arg)
+       (yylex):
+       * src/preproc/pic/main.cpp (do_picture):
+       * src/preproc/pic/object.cpp
+       (output::set_args)
+       (graphic_object::set_fill_color)
+       (graphic_object::set_outline_color)
+       (closed_object::set_fill_color):
+       (polygon_object::set_fill_color):
+       * src/preproc/pic/pic.ypp (do_sprintf):
+       * src/preproc/pic/troff.cpp (troff_output::set_color): Migrate
+       from libgroff's `strsave()` to POSIX's strdup(3).
+
+       Continues the long process of fixing Savannah #66672.
+
 2026-11-16  G. Branden Robinson <[email protected]>
 
        * src/preproc/pic/lex.ypp (get_token)
diff --git a/src/preproc/pic/lex.cpp b/src/preproc/pic/lex.cpp
index 5299d6740..81c4aa446 100644
--- a/src/preproc/pic/lex.cpp
+++ b/src/preproc/pic/lex.cpp
@@ -27,10 +27,10 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 #include <math.h> // pow()
 #include <stdcountof.h>
 #include <stdio.h> // EOF, FILE, fclose(), fopen(), getc(), ungetc()
-#include <string.h> // strerror()
+#include <string.h> // strdup(), strerror()
 
 #include "cset.h" // csdigit(), csupper()
-#include "lib.h" // is_invalid_input_char(), strsave()
+#include "lib.h" // is_invalid_input_char()
 
 #include "pic.h"
 #include "pic.hpp"
@@ -154,7 +154,7 @@ int file_input::get_location(const char **fnp, int *lnp)
 
 macro_input::macro_input(const char *str)
 {
-  p = s = strsave(str);
+  p = s = strdup(str);
 }
 
 macro_input::~macro_input()
@@ -425,7 +425,7 @@ static void interpolate_macro_with_args(const char *body)
          }
          else if (token_buffer.length() > 0) {
            token_buffer += '\0';
-           argv[argc] = strsave(token_buffer.contents());
+           argv[argc] = strdup(token_buffer.contents());
          }
        }
        // for 'foo()', argc = 0
@@ -1432,7 +1432,7 @@ static void do_define()
   if (!get_delimited())
     return;
   token_buffer += '\0';
-  macro_table.define(name, strsave(token_buffer.contents()));
+  macro_table.define(name, strdup(token_buffer.contents()));
 }
 
 static void do_undef()
@@ -1635,7 +1635,7 @@ copy_thru_input::copy_thru_input(const char *b, const 
char *u)
   ap = 0;
   body = process_body(b);
   p = 0;
-  until = strsave(u);
+  until = strdup(u);
 }
 
 
@@ -1843,14 +1843,14 @@ static char *get_thru_arg()
     token_buffer += '\0';
     char *def = macro_table.lookup(token_buffer.contents());
     if (def != 0 /* nullptr */)
-      return strsave(def);
+      return strdup(def);
     // I guess it wasn't a macro after all; so push the macro name back.
     for (size_t i = (token_buffer.length() - 1); i > 0; i--)
       input_stack::push_back(token_buffer[(i - 1)]);
   }
   if (get_delimited()) {
     token_buffer += '\0';
-    return strsave(token_buffer.contents());
+    return strdup(token_buffer.contents());
   }
   else
     return 0 /* nullptr */;
@@ -1882,7 +1882,7 @@ int yylex()
     else {
       if (get_delimited()) {
        token_buffer += '\0';
-       yylval.str = strsave(token_buffer.contents());
+       yylval.str = strdup(token_buffer.contents());
        return DELIMITED;
       }
       else
@@ -1922,12 +1922,12 @@ int yylex()
        yylval.lstr.filename = 0;
        yylval.lstr.lineno = -1;
       }
-      yylval.lstr.str = strsave(token_buffer.contents());
+      yylval.lstr.str = strdup(token_buffer.contents());
       return t;
     case LABEL:
     case VARIABLE:
       token_buffer += '\0';
-      yylval.str = strsave(token_buffer.contents());
+      yylval.str = strdup(token_buffer.contents());
       return t;
     case LEFT:
       // change LEFT to LEFT_CORNER when followed by OF
@@ -1950,7 +1950,7 @@ int yylex()
       old_context_buffer = context_buffer;
       lookahead_token = get_token();
       if (lookahead_token != LEFT && lookahead_token != RIGHT) {
-       yylval.str = strsave("upper");
+       yylval.str = strdup("upper");
        return VARIABLE;
       }
       else
@@ -1960,7 +1960,7 @@ int yylex()
       old_context_buffer = context_buffer;
       lookahead_token = get_token();
       if (lookahead_token != LEFT && lookahead_token != RIGHT) {
-       yylval.str = strsave("lower");
+       yylval.str = strdup("lower");
        return VARIABLE;
       }
       else
@@ -1970,7 +1970,7 @@ int yylex()
       old_context_buffer = context_buffer;
       lookahead_token = get_token();
       if (lookahead_token != OF) {
-       yylval.str = strsave("north");
+       yylval.str = strdup("north");
        return VARIABLE;
       }
       else
@@ -1980,7 +1980,7 @@ int yylex()
       old_context_buffer = context_buffer;
       lookahead_token = get_token();
       if (lookahead_token != OF) {
-       yylval.str = strsave("south");
+       yylval.str = strdup("south");
        return VARIABLE;
       }
       else
@@ -1990,7 +1990,7 @@ int yylex()
       old_context_buffer = context_buffer;
       lookahead_token = get_token();
       if (lookahead_token != OF) {
-       yylval.str = strsave("east");
+       yylval.str = strdup("east");
        return VARIABLE;
       }
       else
@@ -2000,7 +2000,7 @@ int yylex()
       old_context_buffer = context_buffer;
       lookahead_token = get_token();
       if (lookahead_token != OF) {
-       yylval.str = strsave("west");
+       yylval.str = strdup("west");
        return VARIABLE;
       }
       else
@@ -2010,7 +2010,7 @@ int yylex()
       old_context_buffer = context_buffer;
       lookahead_token = get_token();
       if (lookahead_token != OF) {
-       yylval.str = strsave("top");
+       yylval.str = strdup("top");
        return VARIABLE;
       }
       else
@@ -2020,7 +2020,7 @@ int yylex()
       old_context_buffer = context_buffer;
       lookahead_token = get_token();
       if (lookahead_token != OF) {
-       yylval.str = strsave("bottom");
+       yylval.str = strdup("bottom");
        return VARIABLE;
       }
       else
@@ -2030,7 +2030,7 @@ int yylex()
       old_context_buffer = context_buffer;
       lookahead_token = get_token();
       if (lookahead_token != OF) {
-       yylval.str = strsave("center");
+       yylval.str = strdup("center");
        return VARIABLE;
       }
       else
@@ -2040,7 +2040,7 @@ int yylex()
       old_context_buffer = context_buffer;
       lookahead_token = get_token();
       if (lookahead_token != OF) {
-       yylval.str = strsave("start");
+       yylval.str = strdup("start");
        return VARIABLE;
       }
       else
@@ -2050,7 +2050,7 @@ int yylex()
       old_context_buffer = context_buffer;
       lookahead_token = get_token();
       if (lookahead_token != OF) {
-       yylval.str = strsave("end");
+       yylval.str = strdup("end");
        return VARIABLE;
       }
       else
diff --git a/src/preproc/pic/main.cpp b/src/preproc/pic/main.cpp
index 171ccf55e..67be5ec47 100644
--- a/src/preproc/pic/main.cpp
+++ b/src/preproc/pic/main.cpp
@@ -30,11 +30,10 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
                   // fprintf(), fputs(), getc(), printf(), setbuf(),
                   // stderr, stdin, stdout, ungetc()
 #include <stdlib.h> // exit(), EXIT_FAILURE, EXIT_SUCCESS, free()
-#include <string.h> // strerror()
+#include <string.h> // strdup(), strerror()
 
 #include <getopt.h> // getopt_long()
 
-#include "lib.h" // strsave()
 #include "stringclass.h" // prerequisite of "lf.h"
 #include "lf.h" // normalize_file_name_for_lf_request()
 
@@ -237,7 +236,7 @@ static void do_picture(FILE *fp)
   int c;
   if (!graphname)
     free(graphname);
-  graphname = strsave("graph");                // default picture name in TeX 
mode
+  graphname = strdup("graph"); // default picture name in TeX mode
   while ((c = getc(fp)) == ' ')
     ;
   if (c == '<') {
@@ -262,7 +261,7 @@ static void do_picture(FILE *fp)
       const char *old_filename = current_filename;
       int old_lineno = current_lineno;
       // filenames must be permanent
-      do_file(strsave(filename.contents()));
+      do_file(strdup(filename.contents()));
       current_filename = old_filename;
       current_lineno = old_lineno;
     }
diff --git a/src/preproc/pic/object.cpp b/src/preproc/pic/object.cpp
index e128d4df5..c9a586498 100644
--- a/src/preproc/pic/object.cpp
+++ b/src/preproc/pic/object.cpp
@@ -25,9 +25,9 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 #include <assert.h>
 #include <math.h> // M_PI, acos(), atan2(), cos(), sin()
 #include <stdlib.h> // free()
+#include <string.h> // strdup()
 
 #include "cset.h" // csupper()
-#include "lib.h" // strsave()
 
 #include "pic.h"
 
@@ -59,7 +59,7 @@ void output::set_args(const char *s)
   if (s == 0 || *s == '\0')
     args = 0;
   else
-    args = strsave(s);
+    args = strdup(s);
 }
 
 int output::supports_filled_polygons()
@@ -631,12 +631,12 @@ void graphic_object::set_yslanted(double)
 
 void graphic_object::set_fill_color(char *c)
 {
-  color_fill = strsave(c);
+  color_fill = strdup(c);
 }
 
 void graphic_object::set_outline_color(char *c)
 {
-  outline_color = strsave(c);
+  outline_color = strdup(c);
 }
 
 char *graphic_object::get_outline_color()
@@ -779,7 +779,7 @@ void closed_object::set_yslanted(double s)
 
 void closed_object::set_fill_color(char *f)
 {
-  color_fill = strsave(f);
+  color_fill = strdup(f);
 }
 
 class box_object : public closed_object {
@@ -1524,7 +1524,7 @@ void polygon_object::set_fill(double f)
 
 void polygon_object::set_fill_color(char *f)
 {
-  color_fill = strsave(f);
+  color_fill = strdup(f);
 }
 
 void polygon_object::set_vertex_number(int vnum) {
diff --git a/src/preproc/pic/pic.ypp b/src/preproc/pic/pic.ypp
index 2746306b3..0620cc444 100644
--- a/src/preproc/pic/pic.ypp
+++ b/src/preproc/pic/pic.ypp
@@ -31,7 +31,8 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 #include <stdcountof.h>
 #include <stdio.h> // fflush(), fprintf(), snprintf(), sprintf(), stderr
 #include <stdlib.h> // rand(), srand(), system()
-#include <string.h> // strcat(), strchr(), strcmp(), strcpy(), strlen()
+#include <string.h> // strcat(), strchr(), strcmp(), strcpy(), strdup(),
+                   // strlen()
 
 #ifdef NEED_DECLARATION_RAND
 #undef rand
@@ -53,8 +54,6 @@ extern "C" {
 
 #include <vector>
 
-#include "lib.h" // strsave()
-
 #include "pic.h"
 
 /* Maximum number of characters produced by printf("%g") */
@@ -2032,7 +2031,7 @@ char *do_sprintf(const char *fmt, const double *v, int nv)
       result += *fmt++;
   }
   result += '\0';
-  return strsave(result.contents());
+  return strdup(result.contents());
 }
 
 void clean_up_parser()
diff --git a/src/preproc/pic/troff.cpp b/src/preproc/pic/troff.cpp
index d72fd2b37..b19966225 100644
--- a/src/preproc/pic/troff.cpp
+++ b/src/preproc/pic/troff.cpp
@@ -25,8 +25,7 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 #include <assert.h>
 #include <stdlib.h> // free()
 #include <stdio.h> // fputs(), printf(), putchar(), puts(), stdout
-
-#include "lib.h" // strsave()
+#include <string.h> // strdup()
 
 #include "pic.h"
 #include "common.h"
@@ -537,11 +536,11 @@ void troff_output::set_color(char *color_fill, char 
*color_outlined)
     // but that won't work anyway
     if (color_fill) {
       printf(".fcolor %s\n", color_fill);
-      last_filled = strsave(color_fill);
+      last_filled = strdup(color_fill);
     }
     if (color_outlined) {
       printf(".gcolor %s\n", color_outlined);
-      last_outlined = strsave(color_outlined);
+      last_outlined = strdup(color_outlined);
     }
   }
 }

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

Reply via email to