I went through a lint pass for Coreutils and installed the attached patches. These fix only one or two real (albeit unlikely and/or technical) bugs. Most of them remove "#ifdef lint"s or "IF_LINT"s that should no longer be needed with modern GCC and runtimes, the idea being to lessen the difference between linted and unlinted code. If you're building with older GCC and/or non-GCC you may run into a few glitches, which you can ignore with "make WERROR_CFLAGS=" or with "./configure --disable-gcc-warnings" (the default unless you're building from Git).

The biggest lint-oriented change here is the new macro 'main_exit', which should be used only in main functions and is equivalent to either 'exit' or 'return', depending on whether we're pacifying gcc -fsanitize=leak. Using this macro helped me to eliminate a lot of 'IF_LINT (free (x))' calls.

Comments and/or further fixes welcome of course.
From ad4aa2a6f947967df883c18620517c53e67e19fc Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 01/43] expr: lint cleanup, and introducing main_exit
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This introduces a new macro main_exit, which is useful
for pacifying gcc -fsanitizer=lint and in some cases
means we can remove some ‘IF_LINT’ and ‘ifdef lint’ code.
* src/expr.c (main): Use main_exit, not return.
(docolon): Omit an IF_LINT that GCC no longer needs.
* src/system.h (main_exit): New macro.
---
 src/expr.c   |  4 ++--
 src/system.h | 14 +++++++++++++-
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/expr.c b/src/expr.c
index b8f216243..d0cffe3f7 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -357,7 +357,7 @@ main (int argc, char **argv)
 
   printv (v);
 
-  return null (v);
+  main_exit (null (v));
 }
 
 /* Return a VALUE for I.  */
@@ -585,7 +585,7 @@ trace (fxn)
 static VALUE *
 docolon (VALUE *sv, VALUE *pv)
 {
-  VALUE *v IF_LINT ( = NULL);
+  VALUE *v;
   char const *errmsg;
   struct re_pattern_buffer re_buffer;
   char fastmap[UCHAR_MAX + 1];
diff --git a/src/system.h b/src/system.h
index 9f10579dc..16fcc38e7 100644
--- a/src/system.h
+++ b/src/system.h
@@ -465,13 +465,25 @@ enum
 # define PID_T_MAX TYPE_MAXIMUM (pid_t)
 #endif
 
-/* Use this to suppress gcc's '...may be used before initialized' warnings. */
+/* Use this to suppress gcc warnings.  */
 #ifdef lint
 # define IF_LINT(Code) Code
 #else
 # define IF_LINT(Code) /* empty */
 #endif
 
+/* main_exit should be called only from the main function.  It is
+   equivalent to 'exit'.  When checking for lint it calls 'exit', to
+   pacify gcc -fsanitize=lint which would otherwise have false alarms
+   for pointers in the main function's activation record.  Otherwise
+   it simply returns from 'main'; this used to be what gcc's static
+   checking preferred and may yet be again.  */
+#ifdef lint
+# define main_exit(status) exit (status)
+#else
+# define main_exit(status) return status
+#endif
+
 #ifdef __GNUC__
 # define LIKELY(cond)    __builtin_expect ((cond), 1)
 # define UNLIKELY(cond)  __builtin_expect ((cond), 0)
-- 
2.32.0

From b384f8147ebf219cd88d4fae420f7dcef19b825d Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 02/43] comm: pacify -fsanitizer=leak

* src/comm.c (compare_files): Move exiting code here ...
(main): ... from here, to pacify gcc -fsanitize=leak.
---
 src/comm.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/comm.c b/src/comm.c
index dbb9933b5..9cb7a61b0 100644
--- a/src/comm.c
+++ b/src/comm.c
@@ -248,7 +248,8 @@ check_order (struct linebuffer const *prev,
 /* Compare INFILES[0] and INFILES[1].
    If either is "-", use the standard input for that file.
    Assume that each input file is sorted;
-   merge them and output the result.  */
+   merge them and output the result.
+   Exit the program when done.  */
 
 static void
 compare_files (char **infiles)
@@ -401,6 +402,12 @@ compare_files (char **infiles)
               umaxtostr (total[2], buf3), col_sep,
               _("total"), delim);
     }
+
+  if (issued_disorder_warning[0] || issued_disorder_warning[1])
+    die (EXIT_FAILURE, 0, _("input is not in sorted order"));
+
+  /* Exit here to pacify gcc -fsanitizer=leak.  */
+  exit (EXIT_SUCCESS);
 }
 
 int
@@ -491,9 +498,4 @@ main (int argc, char **argv)
     }
 
   compare_files (argv + optind);
-
-  if (issued_disorder_warning[0] || issued_disorder_warning[1])
-    die (EXIT_FAILURE, 0, _("input is not in sorted order"));
-  else
-    return EXIT_SUCCESS;
 }
-- 
2.32.0

From cf455355f6ba328a669508e162deee4635ca4366 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 03/43] stat: pacify -fsanitizer=leak

* src/stat.c (main):  Use main_exit, not return.
---
 src/stat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/stat.c b/src/stat.c
index e58be55e9..edafd0285 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -1965,5 +1965,5 @@ main (int argc, char *argv[])
            ? do_statfs (argv[i], format)
            : do_stat (argv[i], format, format2));
 
-  return ok ? EXIT_SUCCESS : EXIT_FAILURE;
+  main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
-- 
2.32.0

From a7665d1de1995fe79402d326c2f4bdc012e613ae Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 04/43] tr: pacify -fsanitizer=leak

* src/tr.c (main): Use main_exit, not return.
---
 src/tr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/tr.c b/src/tr.c
index a62d52016..f291d1b8e 100644
--- a/src/tr.c
+++ b/src/tr.c
@@ -1913,5 +1913,5 @@ main (int argc, char **argv)
   if (close (STDIN_FILENO) != 0)
     die (EXIT_FAILURE, errno, _("standard input"));
 
-  return EXIT_SUCCESS;
+  main_exit (EXIT_SUCCESS);
 }
-- 
2.32.0

From 5fe2d0ee0fed3d979cc51289ee441ce1d38d0ade Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 05/43] tsort: pacify -fsanitizer=leak

* src/tsort.c (struct item.balance): Now signed char to save space.
(struct item.printed): New member.
(new_item): Initialize k->printed to false.  Simplify via xzalloc.
(scan_zeros): Use k->printed rather than nulling out string.
(tsort): Move exiting code here ...
(main): ... from here.
(tsort) [lint]: Omit no-longer-needed code.  Instead, set head->printed.
---
 src/tsort.c | 39 +++++++++++----------------------------
 1 file changed, 11 insertions(+), 28 deletions(-)

diff --git a/src/tsort.c b/src/tsort.c
index 56c05940d..28a7a05f6 100644
--- a/src/tsort.c
+++ b/src/tsort.c
@@ -54,7 +54,8 @@ struct item
 {
   char const *str;
   struct item *left, *right;
-  int balance; /* -1, 0, or +1 */
+  signed char balance; /* -1, 0, or +1 */
+  bool printed;
   size_t count;
   struct item *qlink;
   struct successor *top;
@@ -101,17 +102,10 @@ Write totally ordered list consistent with the partial ordering in FILE.\n\
 static struct item *
 new_item (char const *str)
 {
-  struct item *k = xmalloc (sizeof *k);
-
-  k->str = (str ? xstrdup (str): NULL);
-  k->left = k->right = NULL;
-  k->balance = 0;
-
   /* T1. Initialize (COUNT[k] <- 0 and TOP[k] <- ^).  */
-  k->count = 0;
-  k->qlink = NULL;
-  k->top = NULL;
-
+  struct item *k = xzalloc (sizeof *k);
+  if (str)
+    k->str = xstrdup (str);
   return k;
 }
 
@@ -295,7 +289,7 @@ static bool
 scan_zeros (struct item *k)
 {
   /* Ignore strings that have already been printed.  */
-  if (k->count == 0 && k->str)
+  if (k->count == 0 && !k->printed)
     {
       if (head == NULL)
         head = k;
@@ -430,9 +424,9 @@ walk_tree (struct item *root, bool (*action) (struct item *))
     recurse_tree (root->right, action);
 }
 
-/* Do a topological sort on FILE.   Return true if successful.  */
+/* Do a topological sort on FILE.  Exit with appropriate exit status.  */
 
-static bool
+static void
 tsort (char const *file)
 {
   bool ok = true;
@@ -490,12 +484,7 @@ tsort (char const *file)
 
           /* T5. Output front of queue.  */
           puts (head->str);
-#ifdef lint
-          /* suppress valgrind "definitely lost" warnings.  */
-          void *head_str = (void *) head->str;
-          free (head_str);
-#endif
-          head->str = NULL;	/* Avoid printing the same string twice.  */
+          head->printed = true;
           n_strings--;
 
           /* T6. Erase relations.  */
@@ -529,20 +518,16 @@ tsort (char const *file)
         }
     }
 
-  IF_LINT (free (root));
-
   if (fclose (stdin) != 0)
     die (EXIT_FAILURE, errno, "%s",
          is_stdin ? _("standard input") : quotef (file));
 
-  return ok;
+  exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
 
 int
 main (int argc, char **argv)
 {
-  bool ok;
-
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
   setlocale (LC_ALL, "");
@@ -561,7 +546,5 @@ main (int argc, char **argv)
       usage (EXIT_FAILURE);
     }
 
-  ok = tsort (optind == argc ? "-" : argv[optind]);
-
-  return ok ? EXIT_SUCCESS : EXIT_FAILURE;
+  tsort (optind == argc ? "-" : argv[optind]);
 }
-- 
2.32.0

From f528ac80d46d5f64525c45e929b1c18c090731ba Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 06/43] seq: pacify -fsanitizer=leak

* src/seq.c (seq_fast): If successful, exit rather than returning true.
Callers changed.
(main): Use main_exit, not return.
---
 src/seq.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/src/seq.c b/src/seq.c
index ba4b77b9a..725d39290 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -456,9 +456,9 @@ trim_leading_zeros (char const *s)
 }
 
 /* Print all whole numbers from A to B, inclusive -- to stdout, each
-   followed by a newline.  If B < A, return false and print nothing.
-   Otherwise, return true.  */
-static bool
+   followed by a newline.  If B < A, return and print nothing.
+   Otherwise, do all the work and exit.  */
+static void
 seq_fast (char const *a, char const *b, uintmax_t step)
 {
   bool inf = STREQ (b, "inf");
@@ -549,13 +549,13 @@ seq_fast (char const *a, char const *b, uintmax_t step)
       *bufp++ = *terminator;
       if (fwrite (buf, bufp - buf, 1, stdout) != 1)
         io_error ();
-
-      IF_LINT (free (buf));
     }
 
+  if (ok)
+    exit (EXIT_SUCCESS);
+
   free (p0);
   free (q0);
-  return ok;
 }
 
 /* Return true if S consists of at least one digit and no non-digits.  */
@@ -674,8 +674,7 @@ main (int argc, char **argv)
     {
       char const *s1 = n_args == 1 ? "1" : argv[optind];
       char const *s2 = argv[optind + (n_args - 1)];
-      if (seq_fast (s1, s2, step.value))
-        return EXIT_SUCCESS;
+      seq_fast (s1, s2, step.value);
 
       /* Upon any failure, let the more general code deal with it.  */
     }
@@ -717,12 +716,8 @@ main (int argc, char **argv)
       else if (asprintf (&s2, "%0.Lf", last.value) < 0)
         xalloc_die ();
 
-      if (*s1 != '-' && *s2 != '-' && seq_fast (s1, s2, step.value))
-        {
-          IF_LINT (free (s1));
-          IF_LINT (free (s2));
-          return EXIT_SUCCESS;
-        }
+      if (*s1 != '-' && *s2 != '-')
+        seq_fast (s1, s2, step.value);
 
       free (s1);
       free (s2);
@@ -734,5 +729,5 @@ main (int argc, char **argv)
 
   print_numbers (format_str, layout, first.value, step.value, last.value);
 
-  return EXIT_SUCCESS;
+  main_exit (EXIT_SUCCESS);
 }
-- 
2.32.0

From 4abd3bb118274fe449682ab5bec0467b9b9b5ef7 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 07/43] ptx: pacify -fsanitizer=leak
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/ptx.c (unescape_string): Rename from copy_unescaped_string,
and unescape the string in place.  Callers changed.  This way,
we needn’t allocate storage and thus needn’t worry about
-fsanitizer=leak.
---
 src/ptx.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/src/ptx.c b/src/ptx.c
index ab4cddea6..09b54447d 100644
--- a/src/ptx.c
+++ b/src/ptx.c
@@ -288,22 +288,16 @@ matcher_error (void)
   die (EXIT_FAILURE, errno, _("error in regular expression matcher"));
 }
 
-/*------------------------------------------------------.
-| Duplicate string STRING, while evaluating \-escapes.  |
-`------------------------------------------------------*/
+/* Unescape STRING in-place.  */
 
-/* Loosely adapted from GNU sh-utils printf.c code.  */
-
-static char *
-copy_unescaped_string (char const *string)
+static void
+unescape_string (char *string)
 {
-  char *result;			/* allocated result */
   char *cursor;			/* cursor in result */
   int value;			/* value of \nnn escape */
   int length;			/* length of \nnn escape */
 
-  result = xmalloc (strlen (string) + 1);
-  cursor = result;
+  cursor = string;
 
   while (*string)
     {
@@ -399,7 +393,6 @@ copy_unescaped_string (char const *string)
     }
 
   *cursor = '\0';
-  return result;
 }
 
 /*--------------------------------------------------------------------------.
@@ -1880,7 +1873,8 @@ main (int argc, char **argv)
           break;
 
         case 'F':
-          truncation_string = copy_unescaped_string (optarg);
+          truncation_string = optarg;
+          unescape_string (optarg);
           break;
 
         case 'M':
@@ -1896,7 +1890,8 @@ main (int argc, char **argv)
           break;
 
         case 'S':
-          context_regex.string = copy_unescaped_string (optarg);
+          context_regex.string = optarg;
+          unescape_string (optarg);
           break;
 
         case 'T':
@@ -1904,7 +1899,8 @@ main (int argc, char **argv)
           break;
 
         case 'W':
-          word_regex.string = copy_unescaped_string (optarg);
+          word_regex.string = optarg;
+          unescape_string (optarg);
           if (!*word_regex.string)
             word_regex.string = NULL;
           break;
-- 
2.32.0

From 7c92df1b9c8e966b1386c7075712582eec5a35b2 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 08/43] split: pacify -fsanitizer=leak

* src/split.c (lines_rr): New arg FILESP.  All uses changed.
(main): Use main_exit, not return.  Omit unnecessary alignfree.
---
 src/split.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/split.c b/src/split.c
index 533c22f9f..b7a0d0e5b 100644
--- a/src/split.c
+++ b/src/split.c
@@ -1125,12 +1125,14 @@ ofile_open (of_t *files, size_t i_check, size_t nfiles)
 }
 
 /* -n r/[K/]N: Divide file into N chunks in round robin fashion.
+   Use BUF of size BUFSIZE for the buffer, and if allocating storage
+   put its address into *FILESP to pacify -fsanitize=leak.
    When K == 0, we try to keep the files open in parallel.
    If we run out of file resources, then we revert
    to opening and closing each file for each line.  */
 
 static void
-lines_rr (uintmax_t k, uintmax_t n, char *buf, size_t bufsize)
+lines_rr (uintmax_t k, uintmax_t n, char *buf, size_t bufsize, of_t **filesp)
 {
   bool wrapped = false;
   bool wrote = false;
@@ -1145,7 +1147,7 @@ lines_rr (uintmax_t k, uintmax_t n, char *buf, size_t bufsize)
     {
       if (SIZE_MAX < n)
         xalloc_die ();
-      files = xnmalloc (n, sizeof *files);
+      files = *filesp = xnmalloc (n, sizeof *files);
 
       /* Generate output file names. */
       for (i_file = 0; i_file < n; i_file++)
@@ -1269,7 +1271,6 @@ no_filters:
           files[i_file].ofd = OFD_APPEND;
         }
     }
-  IF_LINT (free (files));
 }
 
 #define FAIL_ONLY_ONE_WAY()					\
@@ -1654,18 +1655,19 @@ main (int argc, char **argv)
     case type_rr:
       /* Note, this is like 'sed -n ${k}~${n}p' when k > 0,
          but the functionality is provided for symmetry.  */
-      lines_rr (k_units, n_units, buf, in_blk_size);
+      {
+        of_t *files;
+        lines_rr (k_units, n_units, buf, in_blk_size, &files);
+      }
       break;
 
     default:
       abort ();
     }
 
-  IF_LINT (alignfree (buf));
-
   if (close (STDIN_FILENO) != 0)
     die (EXIT_FAILURE, errno, "%s", quotef (infile));
   closeout (NULL, output_desc, filter_pid, outfile);
 
-  return EXIT_SUCCESS;
+  main_exit (EXIT_SUCCESS);
 }
-- 
2.32.0

From 038dae839cf42d1ac1b475f4a1cc9574204c9743 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 09/43] sort: pacify -fsanitizer=leak

* src/sort.c (pipe_fork, keycompare, sort, main):
Remove lint code that no longer seems to be needed.
(sort): Unconditionally compile ifdef lint code that is needed
to free storage even when not linting.
(main): Use main_exit, not return.
---
 src/sort.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/src/sort.c b/src/sort.c
index c55ca5369..1a3bda698 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -1045,7 +1045,7 @@ pipe_fork (int pipefds[2], size_t tries)
   struct tempnode *saved_temphead;
   int saved_errno;
   double wait_retry = 0.25;
-  pid_t pid IF_LINT ( = -1);
+  pid_t pid;
   struct cs_status cs;
 
   if (pipe2 (pipefds, O_CLOEXEC) < 0)
@@ -2648,9 +2648,9 @@ keycompare (struct line const *a, struct line const *b)
           size_t tlena;
           size_t tlenb;
 
-          char enda IF_LINT (= 0);
-          char endb IF_LINT (= 0);
-          void *allocated IF_LINT (= NULL);
+          char enda;
+          char endb;
+          void *allocated;
           char stackbuf[4000];
 
           if (ignore || translate)
@@ -3995,7 +3995,6 @@ sort (char *const *files, size_t nfiles, char const *output_file,
       size_t nthreads)
 {
   struct buffer buf;
-  IF_LINT (buf.buf = NULL);
   size_t ntemps = 0;
   bool output_file_created = false;
 
@@ -4070,10 +4069,8 @@ sort (char *const *files, size_t nfiles, char const *output_file,
               sortlines (line, nthreads, buf.nlines, merge_tree + 1,
                          &queue, tfp, temp_output);
 
-#ifdef lint
               merge_tree_destroy (nthreads, merge_tree);
               queue_destroy (&queue);
-#endif
             }
           else
             write_unique (line - 1, tfp, temp_output);
@@ -4819,7 +4816,7 @@ main (int argc, char **argv)
 
       /* POSIX requires that sort return 1 IFF invoked with -c or -C and the
          input is not properly sorted.  */
-      return check (files[0], checkonly) ? EXIT_SUCCESS : SORT_OUT_OF_ORDER;
+      exit (check (files[0], checkonly) ? EXIT_SUCCESS : SORT_OUT_OF_ORDER);
     }
 
   /* Check all inputs are accessible, or exit immediately.  */
@@ -4836,7 +4833,6 @@ main (int argc, char **argv)
         sortfiles[i].name = files[i];
 
       merge (sortfiles, 0, nfiles, outfile);
-      IF_LINT (free (sortfiles));
     }
   else
     {
@@ -4853,15 +4849,8 @@ main (int argc, char **argv)
       sort (files, nfiles, outfile, nthreads);
     }
 
-#ifdef lint
-  if (files_from)
-    readtokens0_free (&tok);
-  else
-    free (files);
-#endif
-
   if (have_read_stdin && fclose (stdin) == EOF)
     sort_die (_("close failed"), "-");
 
-  return EXIT_SUCCESS;
+  main_exit (EXIT_SUCCESS);
 }
-- 
2.32.0

From 5624acf3a29d4bf81561b5611fd74cc897c40d5f Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 10/43] tsort: pacify -fsanitizer=leak

* src/tsort.c (detect_loop): Free removed successor.
---
 src/tsort.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/tsort.c b/src/tsort.c
index 28a7a05f6..19b991bed 100644
--- a/src/tsort.c
+++ b/src/tsort.c
@@ -352,8 +352,10 @@ detect_loop (struct item *k)
                           if (loop == k)
                             {
                               /* Remove relation.  */
-                              (*p)->suc->count--;
-                              *p = (*p)->next;
+                              struct successor *s = *p;
+                              s->suc->count--;
+                              *p = s->next;
+                              IF_LINT (free (s));
                               break;
                             }
 
-- 
2.32.0

From a291e9ea61436623463d10148df00fb6b42250dc Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 11/43] yes: pacify -fsanitizer=leak

* src/yes.c (main): Use main_exit, not return.
---
 src/yes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/yes.c b/src/yes.c
index dc1791b2e..13b990e24 100644
--- a/src/yes.c
+++ b/src/yes.c
@@ -126,5 +126,5 @@ main (int argc, char **argv)
   while (full_write (STDOUT_FILENO, buf, bufused) == bufused)
     continue;
   error (0, errno, _("standard output"));
-  return EXIT_FAILURE;
+  main_exit (EXIT_FAILURE);
 }
-- 
2.32.0

From 9ecf5c8834896205b1aaec6d3dd3629807eaab4a Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 12/43] chmod: pacify -fsanitizer=leak

* src/chmod.c (main): Use main_exit, not return.
---
 src/chmod.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/chmod.c b/src/chmod.c
index 3776a7e05..81dd3192c 100644
--- a/src/chmod.c
+++ b/src/chmod.c
@@ -567,7 +567,5 @@ main (int argc, char **argv)
   ok = process_files (argv + optind,
                       FTS_COMFOLLOW | FTS_PHYSICAL | FTS_DEFER_STAT);
 
-  IF_LINT (free (change));
-
-  return ok ? EXIT_SUCCESS : EXIT_FAILURE;
+  main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
-- 
2.32.0

From 5080aa5faa80c516888c97a5aa94a2c2a80e993f Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 13/43] cp: simplify cp/install/ln/mv pacification
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/copy.c (dest_info_free, src_info_free) [lint]:
Remove.  All uses removed.
(copy_internal): Pacify only Clang and Coverity; GCC doesn’t need it.
* src/cp-hash.c (forget_all) [lint]: Remove.  All uses removed.
* src/cp.c, src/install.c, src/ln.c, src/mv.c (main):
Use main_exit, not return.
---
 src/copy.c    | 24 ++----------------------
 src/cp-hash.c | 11 -----------
 src/cp-hash.h |  1 -
 src/cp.c      | 11 +----------
 src/install.c |  5 +----
 src/ln.c      |  8 +-------
 src/mv.c      |  6 +-----
 7 files changed, 6 insertions(+), 60 deletions(-)

diff --git a/src/copy.c b/src/copy.c
index 4a7d9b5d9..33a26c36a 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -1759,16 +1759,6 @@ dest_info_init (struct cp_options *x)
     xalloc_die ();
 }
 
-#ifdef lint
-extern void
-dest_info_free (struct cp_options *x)
-{
-  if (x->dest_info)
-    hash_free (x->dest_info);
-  x->dest_info = NULL;
-}
-#endif
-
 /* Initialize the hash table implementing a set of F_triple entries
    corresponding to source files listed on the command line.  */
 extern void
@@ -1793,16 +1783,6 @@ src_info_init (struct cp_options *x)
     xalloc_die ();
 }
 
-#ifdef lint
-extern void
-src_info_free (struct cp_options *x)
-{
-  if (x->src_info)
-    hash_free (x->src_info);
-  x->src_info = NULL;
-}
-#endif
-
 /* When effecting a move (e.g., for mv(1)), and given the name DST_NAME
    aka DST_DIRFD+DST_RELNAME
    of the destination and a corresponding stat buffer, DST_SB, return
@@ -2014,13 +1994,13 @@ copy_internal (char const *src_name, char const *dst_name,
           return false;
         }
     }
-#ifdef lint
   else
     {
+#if defined lint && (defined __clang__ || defined __COVERITY__)
       assert (x->move_mode);
       memset (&src_sb, 0, sizeof src_sb);
-    }
 #endif
+    }
 
   /* Detect the case in which the same source file appears more than
      once on the command line and no backup option has been selected.
diff --git a/src/cp-hash.c b/src/cp-hash.c
index 3a3a07490..e566a4c4a 100644
--- a/src/cp-hash.c
+++ b/src/cp-hash.c
@@ -153,14 +153,3 @@ hash_init (void)
   if (src_to_dest == NULL)
     xalloc_die ();
 }
-
-/* Reset the hash structure in the global variable 'htab' to
-   contain no entries.  */
-
-#ifdef lint
-extern void
-forget_all (void)
-{
-  hash_free (src_to_dest);
-}
-#endif
diff --git a/src/cp-hash.h b/src/cp-hash.h
index 72870fa6d..989fcc53b 100644
--- a/src/cp-hash.h
+++ b/src/cp-hash.h
@@ -1,5 +1,4 @@
 void hash_init (void);
-void forget_all (void);
 void forget_created (ino_t ino, dev_t dev);
 char *remember_copied (char const *node, ino_t ino, dev_t dev)
   _GL_ATTRIBUTE_NONNULL ();
diff --git a/src/cp.c b/src/cp.c
index d680eb01d..5084037f1 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -735,11 +735,6 @@ do_copy (int n_files, char **file, char const *target_directory,
 
           free (dst_name);
         }
-
-#ifdef lint
-      dest_info_free (x);
-      src_info_free (x);
-#endif
     }
   else /* !target_directory */
     {
@@ -1218,9 +1213,5 @@ main (int argc, char **argv)
   ok = do_copy (argc - optind, argv + optind,
                 target_directory, no_target_directory, &x);
 
-#ifdef lint
-  forget_all ();
-#endif
-
-  return ok ? EXIT_SUCCESS : EXIT_FAILURE;
+  main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
diff --git a/src/install.c b/src/install.c
index a27a5343b..38e26a887 100644
--- a/src/install.c
+++ b/src/install.c
@@ -1023,11 +1023,8 @@ main (int argc, char **argv)
                                        i == 0 && mkdir_and_install,
                                        &target_dirfd))
               exit_status = EXIT_FAILURE;
-#ifdef lint
-          dest_info_free (&x);
-#endif
         }
     }
 
-  return exit_status;
+  main_exit (exit_status);
 }
diff --git a/src/ln.c b/src/ln.c
index 5a05c078c..bb4695853 100644
--- a/src/ln.c
+++ b/src/ln.c
@@ -674,15 +674,9 @@ main (int argc, char **argv)
           ok &= do_link (file[i], destdir_fd, dest_base, dest, -1);
           free (dest);
         }
-
-#ifdef lint
-      if (dest_set)
-        hash_free (dest_set);
-      dest_set = NULL;
-#endif
     }
   else
     ok = do_link (file[0], AT_FDCWD, file[1], file[1], link_errno);
 
-  return ok ? EXIT_SUCCESS : EXIT_FAILURE;
+  main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
diff --git a/src/mv.c b/src/mv.c
index fcf32cd43..21018a0d3 100644
--- a/src/mv.c
+++ b/src/mv.c
@@ -487,10 +487,6 @@ main (int argc, char **argv)
           ok &= do_move (source, dest, target_dirfd, dest_relname, &x);
           free (dest);
         }
-
-#ifdef lint
-      dest_info_free (&x);
-#endif
     }
   else
     {
@@ -498,5 +494,5 @@ main (int argc, char **argv)
       ok = do_move (file[0], file[1], AT_FDCWD, file[1], &x);
     }
 
-  return ok ? EXIT_SUCCESS : EXIT_FAILURE;
+  main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
-- 
2.32.0

From b56827f9e48a34c9ca40a14dad886bb774a71861 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 14/43] dd: simplify -fsanitize=leak pacification

* src/dd.c (cleanup) [lint]: Omit unnecessary cleanup.
(main): Use main_exit, not return.
---
 src/dd.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/src/dd.c b/src/dd.c
index 4ddc6db12..e55f87f14 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -944,12 +944,6 @@ static int synchronize_output (void);
 static void
 cleanup (void)
 {
-#ifdef lint
-  if (ibuf != obuf)
-    alignfree (ibuf);
-  alignfree (obuf);
-#endif
-
   if (!interrupt_signal)
     {
       int sync_status = synchronize_output ();
@@ -2572,5 +2566,5 @@ main (int argc, char **argv)
     }
 
   finish_up ();
-  return exit_status;
+  main_exit (exit_status);
 }
-- 
2.32.0

From ea81e13f24715cdb88f26176b43fdac394bec2d5 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 15/43] mktemp: simplify -fsanitize=leak pacification

* src/mktemp.c (main) [lint]: Omit unnecessary cleanup.
Use main_exit, not return.
---
 src/mktemp.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/src/mktemp.c b/src/mktemp.c
index 4c11d04d1..9edcf5415 100644
--- a/src/mktemp.c
+++ b/src/mktemp.c
@@ -341,10 +341,5 @@ main (int argc, char **argv)
         }
     }
 
-#ifdef lint
-  free (dest_name);
-  free (template);
-#endif
-
-  return status;
+  main_exit (status);
 }
-- 
2.32.0

From b5da6c13f8e293af303a71b63b706acd73bec359 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 16/43] numfmt: simplify -fsanitize=leak pacification

* src/numfmt.c (main) [lint]: Omit unnecessary cleanup.
Use main_exit, not return.
---
 src/numfmt.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/src/numfmt.c b/src/numfmt.c
index 578aa558a..fccb47480 100644
--- a/src/numfmt.c
+++ b/src/numfmt.c
@@ -1627,19 +1627,10 @@ main (int argc, char **argv)
           valid_numbers &= process_line (line, newline);
         }
 
-      IF_LINT (free (line));
-
       if (ferror (stdin))
         error (0, errno, _("error reading input"));
     }
 
-#ifdef lint
-  free (padding_buffer);
-  free (format_str_prefix);
-  free (format_str_suffix);
-  reset_fields ();
-#endif
-
   if (debug && !valid_numbers)
     error (0, 0, _("failed to convert some of the input numbers"));
 
@@ -1648,5 +1639,5 @@ main (int argc, char **argv)
       && inval_style != inval_warn && inval_style != inval_ignore)
     exit_status = EXIT_CONVERSION_WARNINGS;
 
-  return exit_status;
+  main_exit (exit_status);
 }
-- 
2.32.0

From d034c1ee0c5b7d442d1ef6a66b995f74f13ce930 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 17/43] shuf: simplify -fsanitize=leak pacification

* src/shuf.c (main) [lint]: Omit unnecessary cleanup.
Use main_exit, not return.
---
 src/shuf.c | 19 +------------------
 1 file changed, 1 insertion(+), 18 deletions(-)

diff --git a/src/shuf.c b/src/shuf.c
index 7f696d6b0..68ca609eb 100644
--- a/src/shuf.c
+++ b/src/shuf.c
@@ -595,22 +595,5 @@ main (int argc, char **argv)
   if (i != 0)
     die (EXIT_FAILURE, errno, _("write error"));
 
-#ifdef lint
-  free (permutation);
-  randint_all_free (randint_source);
-  if (input_lines)
-    {
-      free (input_lines[0]);
-      free (input_lines);
-    }
-  if (reservoir)
-    {
-      size_t j;
-      for (j = 0; j < n_lines; ++j)
-        freebuffer (&reservoir[j]);
-      free (reservoir);
-    }
-#endif
-
-  return EXIT_SUCCESS;
+  main_exit (EXIT_SUCCESS);
 }
-- 
2.32.0

From f9e70c6ddfe4e14459098f166620555ed686b9a4 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 18/43] tac: simplify -fsanitize=leak pacification

* src/tac.c (main) [lint]: Omit unnecessary cleanup.
Use main_exit, not return.
---
 src/tac.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/src/tac.c b/src/tac.c
index f1614f2cf..fd3778250 100644
--- a/src/tac.c
+++ b/src/tac.c
@@ -704,10 +704,5 @@ main (int argc, char **argv)
       ok = false;
     }
 
-#ifdef lint
-  size_t offset = sentinel_length ? sentinel_length : 1;
-  free (G_buffer - offset);
-#endif
-
-  return ok ? EXIT_SUCCESS : EXIT_FAILURE;
+  main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
-- 
2.32.0

From 7c2dd489eef2ebdfb35f58cd8391f2c315c98cfa Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 19/43] tail: simplify -fsanitize=leak pacification
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Also, close a no-longer-needed file descriptor when falling
back from inotify.
* src/tail.c (tail_forever_inotify): Return void, not bool.  Exit
on fatal error, or on successful completion.  Accept an extra
argument pointing to a hash table that the caller should free on
non-fatal error; this simplifies cleanup.  Don’t bother setting
errno when returning.  Caller changed.
(main): Omit no-longer-needed IF_LINT code.  Close inotify
descriptor if inotify fails; this fixes a file descriptor leak and
means we needn’t call inotify_rm_watch.  Use main_exit, not return.
---
 src/tail.c | 68 +++++++++++++-----------------------------------------
 1 file changed, 16 insertions(+), 52 deletions(-)

diff --git a/src/tail.c b/src/tail.c
index fe564797e..f1b741783 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1451,10 +1451,10 @@ check_fspec (struct File_spec *fspec, struct File_spec **prev_fspec)
 
 /* Attempt to tail N_FILES files forever, or until killed.
    Check modifications using the inotify events system.
-   Return false on error, or true to revert to polling.  */
-static bool
+   Exit if finished or on fatal error; return to revert to polling.  */
+static void
 tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
-                      double sleep_interval)
+                      double sleep_interval, Hash_table **wd_to_namep)
 {
 # if TAIL_TEST_SLEEP
   /* Delay between open() and inotify_add_watch()
@@ -1480,6 +1480,7 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
   wd_to_name = hash_initialize (n_files, NULL, wd_hasher, wd_comparator, NULL);
   if (! wd_to_name)
     xalloc_die ();
+  *wd_to_namep = wd_to_name;
 
   /* The events mask used with inotify on files (not directories).  */
   uint32_t inotify_wd_mask = IN_MODIFY;
@@ -1564,19 +1565,9 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
      tailed but unwatchable due rename/unlink race, should also revert.  */
   if (no_inotify_resources || found_unwatchable_dir
       || (follow_mode == Follow_descriptor && tailed_but_unwatchable))
-    {
-      hash_free (wd_to_name);
-
-      errno = 0;
-      return true;
-    }
+    return;
   if (follow_mode == Follow_descriptor && !found_watchable_file)
-    {
-# ifdef lint
-      hash_free (wd_to_name);
-# endif
-      return false;
-    }
+    exit (EXIT_FAILURE);
 
   prev_fspec = &(f[n_files - 1]);
 
@@ -1602,10 +1593,7 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
                 {
                   error (0, errno, _("%s was replaced"),
                          quoteaf (pretty_name (&(f[i]))));
-                  hash_free (wd_to_name);
-
-                  errno = 0;
-                  return true;
+                  return;
                 }
             }
 
@@ -1632,13 +1620,7 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
       if (follow_mode == Follow_name
           && ! reopen_inaccessible_files
           && hash_get_n_entries (wd_to_name) == 0)
-        {
-          error (0, 0, _("no files remaining"));
-# ifdef lint
-          hash_free (wd_to_name);
-# endif
-          return false;
-        }
+        die (EXIT_FAILURE, 0, _("no files remaining"));
 
       if (len <= evbuf_off)
         {
@@ -1717,11 +1699,9 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
             {
               if (ev->wd == f[i].parent_wd)
                 {
-                  hash_free (wd_to_name);
                   error (0, 0,
                       _("directory containing watched file was removed"));
-                  errno = 0;  /* we've already diagnosed enough errno detail. */
-                  return true;
+                  return;
                 }
             }
         }
@@ -1758,9 +1738,7 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
               if (errno == ENOSPC || errno == ENOMEM)
                 {
                   error (0, 0, _("inotify resources exhausted"));
-                  hash_free (wd_to_name);
-                  errno = 0;
-                  return true; /* revert to polling.  */
+                  return; /* revert to polling.  */
                 }
               else
                 {
@@ -2382,8 +2360,6 @@ main (int argc, char **argv)
         --n_units;
     }
 
-  IF_LINT (assert (0 <= argc));
-
   if (optind < argc)
     {
       n_files = argc - optind;
@@ -2509,32 +2485,20 @@ main (int argc, char **argv)
               if (fflush (stdout) != 0)
                 die (EXIT_FAILURE, errno, _("write error"));
 
-              if (! tail_forever_inotify (wd, F, n_files, sleep_interval))
-                return EXIT_FAILURE;
+              Hash_table *ht;
+              tail_forever_inotify (wd, F, n_files, sleep_interval, &ht);
+              hash_free (ht);
+              close (wd);
+              errno = 0;
             }
           error (0, errno, _("inotify cannot be used, reverting to polling"));
-
-          /* Free resources as this process can be long lived,
-            and we may have exhausted system resources above.  */
-
-          for (i = 0; i < n_files; i++)
-            {
-              /* It's OK to remove the same watch multiple times,
-                ignoring the EINVAL from redundant calls.  */
-              if (F[i].wd != -1)
-                inotify_rm_watch (wd, F[i].wd);
-              if (F[i].parent_wd != -1)
-                inotify_rm_watch (wd, F[i].parent_wd);
-            }
         }
 #endif
       disable_inotify = true;
       tail_forever (F, n_files, sleep_interval);
     }
 
-  IF_LINT (free (F));
-
   if (have_read_stdin && close (STDIN_FILENO) < 0)
     die (EXIT_FAILURE, errno, "-");
-  return ok ? EXIT_SUCCESS : EXIT_FAILURE;
+  main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
-- 
2.32.0

From 2475dc26cd3be7322fa21fb47759820677b39744 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 20/43] test: simplify gcc pacification

* src/test.c (get_mtime) [lint]: Omit ifdef lint code that is no
longer needed, as GCC has gotten smarter since 2005.
---
 src/test.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/src/test.c b/src/test.c
index f154199ce..6daad3b34 100644
--- a/src/test.c
+++ b/src/test.c
@@ -168,10 +168,6 @@ get_mtime (char const *filename, struct timespec *mtime)
 {
   struct stat finfo;
   bool ok = (stat (filename, &finfo) == 0);
-#ifdef lint
-  static struct timespec const zero;
-  *mtime = zero;
-#endif
   if (ok)
     *mtime = get_stat_mtime (&finfo);
   return ok;
-- 
2.32.0

From 4570e01be4f8ee184a71f161ef86f91fda8ad4ae Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 21/43] basenc: simplify -fsanitize=leak pacification

* src/basenc.c (finish_and_exit): New function.
(do_encode, do_decode): Use it.  Accept new INFILE arg.  Remove
no-longer-needed IF_LINT code.  Exit when done.  Caller changed.
---
 src/basenc.c | 41 ++++++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/src/basenc.c b/src/basenc.c
index ff8ea99c0..b37545929 100644
--- a/src/basenc.c
+++ b/src/basenc.c
@@ -950,7 +950,21 @@ wrap_write (char const *buffer, idx_t len,
 }
 
 static void
-do_encode (FILE *in, FILE *out, idx_t wrap_column)
+finish_and_exit (FILE *in, char const *infile)
+{
+  if (fclose (in) != 0)
+    {
+      if (STREQ (infile, "-"))
+        die (EXIT_FAILURE, errno, _("closing standard input"));
+      else
+        die (EXIT_FAILURE, errno, "%s", quotef (infile));
+    }
+
+  exit (EXIT_SUCCESS);
+}
+
+static void
+do_encode (FILE *in, char const *infile, FILE *out, idx_t wrap_column)
 {
   idx_t current_column = 0;
   char *inbuf, *outbuf;
@@ -990,12 +1004,11 @@ do_encode (FILE *in, FILE *out, idx_t wrap_column)
   if (ferror (in))
     die (EXIT_FAILURE, errno, _("read error"));
 
-  IF_LINT (free (inbuf));
-  IF_LINT (free (outbuf));
+  finish_and_exit (in, infile);
 }
 
 static void
-do_decode (FILE *in, FILE *out, bool ignore_garbage)
+do_decode (FILE *in, char const *infile, FILE *out, bool ignore_garbage)
 {
   char *inbuf, *outbuf;
   idx_t sum;
@@ -1057,11 +1070,7 @@ do_decode (FILE *in, FILE *out, bool ignore_garbage)
     }
   while (!feof (in));
 
-#if BASE_TYPE == 42
-  IF_LINT (free (ctx.inbuf));
-#endif
-  IF_LINT (free (inbuf));
-  IF_LINT (free (outbuf));
+  finish_and_exit (in, infile);
 }
 
 int
@@ -1233,17 +1242,7 @@ main (int argc, char **argv)
   fadvise (input_fh, FADVISE_SEQUENTIAL);
 
   if (decode)
-    do_decode (input_fh, stdout, ignore_garbage);
+    do_decode (input_fh, infile, stdout, ignore_garbage);
   else
-    do_encode (input_fh, stdout, wrap_column);
-
-  if (fclose (input_fh) == EOF)
-    {
-      if (STREQ (infile, "-"))
-        die (EXIT_FAILURE, errno, _("closing standard input"));
-      else
-        die (EXIT_FAILURE, errno, "%s", quotef (infile));
-    }
-
-  return EXIT_SUCCESS;
+    do_encode (input_fh, infile, stdout, wrap_column);
 }
-- 
2.32.0

From da680741df492042a950c16939846488de02876f Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 22/43] chown: simplify -fsanitize=leak pacification

* src/chgrp.c, src/chown.c (main) [lint]: Omit unnecessary cleanup.
Use main_exit, not return.
---
 src/chgrp.c | 4 +---
 src/chown.c | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/chgrp.c b/src/chgrp.c
index ac5a3eefd..0c0f62949 100644
--- a/src/chgrp.c
+++ b/src/chgrp.c
@@ -313,7 +313,5 @@ main (int argc, char **argv)
                     (uid_t) -1, gid,
                     (uid_t) -1, (gid_t) -1, &chopt);
 
-  IF_LINT (chopt_free (&chopt));
-
-  return ok ? EXIT_SUCCESS : EXIT_FAILURE;
+  exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
diff --git a/src/chown.c b/src/chown.c
index 90f3bc9c0..329b0f4dc 100644
--- a/src/chown.c
+++ b/src/chown.c
@@ -325,7 +325,5 @@ main (int argc, char **argv)
                     uid, gid,
                     required_uid, required_gid, &chopt);
 
-  IF_LINT (chopt_free (&chopt));
-
-  return ok ? EXIT_SUCCESS : EXIT_FAILURE;
+  main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
-- 
2.32.0

From 2d5440843d842b371044781769c3eff1b73eb899 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 23/43] cp: simplify GCC pacification

* src/cp.c (make_dir_parents_private): Remove IF_LINT code that is
no longer needed, as GCC has apparently gotten smarter since 2008.
---
 src/cp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/cp.c b/src/cp.c
index 5084037f1..b73f2cb49 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -404,7 +404,7 @@ make_dir_parents_private (char const *const_dir, size_t src_offset,
 
       while ((slash = strchr (slash, '/')))
         {
-          struct dir_attr *new IF_LINT ( = NULL);
+          struct dir_attr *new;
           bool missing_dir;
 
           *slash = '\0';
-- 
2.32.0

From 1b161c3404f1d781ac95c4ad29e21ec1f61e63b6 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 24/43] cut: simplify -fsanitize=leak pacification
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/set-fields.c (reset_fields): Remove, as it’s not needed for
-fsanitize=leak even when ‘lint’ is defined.  All uses removed.
---
 src/cut.c        | 2 --
 src/set-fields.c | 9 ---------
 src/set-fields.h | 3 ---
 3 files changed, 14 deletions(-)

diff --git a/src/cut.c b/src/cut.c
index 5143c8bd9..ac874c3f8 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -602,7 +602,5 @@ main (int argc, char **argv)
       ok = false;
     }
 
-  IF_LINT (reset_fields ());
-
   return ok ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/src/set-fields.c b/src/set-fields.c
index e3cce30d9..575dc2784 100644
--- a/src/set-fields.c
+++ b/src/set-fields.c
@@ -308,12 +308,3 @@ set_fields (char const *fieldstr, unsigned int options)
   frp = xrealloc (frp, n_frp * sizeof (struct field_range_pair));
   frp[n_frp - 1].lo = frp[n_frp - 1].hi = UINTMAX_MAX;
 }
-
-void
-reset_fields (void)
-{
-  n_frp = 0 ;
-  n_frp_allocated = 0;
-  free (frp);
-  frp = NULL;
-}
diff --git a/src/set-fields.h b/src/set-fields.h
index 7bc9b3afe..3e7613a98 100644
--- a/src/set-fields.h
+++ b/src/set-fields.h
@@ -41,7 +41,4 @@ enum
 /* allocates and initializes the FRP array and N_FRP count */
 extern void set_fields (char const *fieldstr, unsigned int options);
 
-/* frees memory allocated by set_fields() */
-extern void reset_fields (void);
-
 #endif
-- 
2.32.0

From 3f40164892425b3052ff596abf688ffb3b0d0d94 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 25/43] cut: simplify and remove an IF_LINT
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/cut.c (enum operating_mode, operating_mode)
(output_delimiter_specified, cut_stream):
Remove; no longer needed.
(output_delimiter_default): New static var.  Code can now
use ‘output_delimiter_string != output_delimiter_default’
instead of ‘output_delimiter_specified’.
(cut_file): New arg CUT_STREAM.  Caller changed.
(main): Simplify.  Coalesce duplicate code.  Redo to avoid need
for IF_LINT, or for the static var.  No need to xstrdup optarg.
---
 src/cut.c | 83 +++++++++++++++++++------------------------------------
 1 file changed, 28 insertions(+), 55 deletions(-)

diff --git a/src/cut.c b/src/cut.c
index ac874c3f8..13967d6ef 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -72,19 +72,6 @@ static char *field_1_buffer;
 /* The number of bytes allocated for FIELD_1_BUFFER.  */
 static size_t field_1_bufsize;
 
-enum operating_mode
-  {
-    undefined_mode,
-
-    /* Output characters that are in the given bytes. */
-    byte_mode,
-
-    /* Output the given delimiter-separated fields. */
-    field_mode
-  };
-
-static enum operating_mode operating_mode;
-
 /* If true do not output lines containing no delimiter characters.
    Otherwise, all such lines are printed.  This option is valid only
    with field mode.  */
@@ -100,9 +87,6 @@ static unsigned char delim;
 /* The delimiter for each line/record. */
 static unsigned char line_delim = '\n';
 
-/* True if the --output-delimiter=STRING option was specified.  */
-static bool output_delimiter_specified;
-
 /* The length of output_delimiter_string.  */
 static size_t output_delimiter_length;
 
@@ -110,6 +94,9 @@ static size_t output_delimiter_length;
    string consisting of the input delimiter.  */
 static char *output_delimiter_string;
 
+/* The output delimiter string contents, if the default.  */
+char output_delimiter_default[1];
+
 /* True if we have ever read standard input. */
 static bool have_read_stdin;
 
@@ -263,7 +250,7 @@ cut_bytes (FILE *stream)
           next_item (&byte_idx);
           if (print_kth (byte_idx))
             {
-              if (output_delimiter_specified)
+              if (output_delimiter_string != output_delimiter_default)
                 {
                   if (print_delimiter && is_range_start_index (byte_idx))
                     {
@@ -424,20 +411,11 @@ cut_fields (FILE *stream)
     }
 }
 
-static void
-cut_stream (FILE *stream)
-{
-  if (operating_mode == byte_mode)
-    cut_bytes (stream);
-  else
-    cut_fields (stream);
-}
-
-/* Process file FILE to standard output.
+/* Process file FILE to standard output, using CUT_STREAM.
    Return true if successful.  */
 
 static bool
-cut_file (char const *file)
+cut_file (char const *file, void (*cut_stream) (FILE *))
 {
   FILE *stream;
 
@@ -481,7 +459,8 @@ main (int argc, char **argv)
   int optc;
   bool ok;
   bool delim_specified = false;
-  char *spec_list_string IF_LINT ( = NULL);
+  bool byte_mode = false;
+  char *spec_list_string = NULL;
 
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
@@ -491,8 +470,6 @@ main (int argc, char **argv)
 
   atexit (close_stdout);
 
-  operating_mode = undefined_mode;
-
   /* By default, all non-delimited lines are printed.  */
   suppress_non_delimited = false;
 
@@ -506,17 +483,12 @@ main (int argc, char **argv)
         case 'b':
         case 'c':
           /* Build the byte list. */
-          if (operating_mode != undefined_mode)
-            FATAL_ERROR (_("only one type of list may be specified"));
-          operating_mode = byte_mode;
-          spec_list_string = optarg;
-          break;
-
+          byte_mode = true;
+          FALLTHROUGH;
         case 'f':
           /* Build the field list. */
-          if (operating_mode != undefined_mode)
-            FATAL_ERROR (_("only one type of list may be specified"));
-          operating_mode = field_mode;
+          if (spec_list_string)
+            FATAL_ERROR (_("only one list may be specified"));
           spec_list_string = optarg;
           break;
 
@@ -530,12 +502,11 @@ main (int argc, char **argv)
           break;
 
         case OUTPUT_DELIMITER_OPTION:
-          output_delimiter_specified = true;
           /* Interpret --output-delimiter='' to mean
              'use the NUL byte as the delimiter.'  */
           output_delimiter_length = (optarg[0] == '\0'
                                      ? 1 : strlen (optarg));
-          output_delimiter_string = xstrdup (optarg);
+          output_delimiter_string = optarg;
           break;
 
         case 'n':
@@ -562,38 +533,40 @@ main (int argc, char **argv)
         }
     }
 
-  if (operating_mode == undefined_mode)
+  if (!spec_list_string)
     FATAL_ERROR (_("you must specify a list of bytes, characters, or fields"));
 
-  if (delim_specified && operating_mode != field_mode)
-    FATAL_ERROR (_("an input delimiter may be specified only\
+  if (byte_mode)
+    {
+      if (delim_specified)
+        FATAL_ERROR (_("an input delimiter may be specified only\
  when operating on fields"));
 
-  if (suppress_non_delimited && operating_mode != field_mode)
-    FATAL_ERROR (_("suppressing non-delimited lines makes sense\n\
+      if (suppress_non_delimited)
+        FATAL_ERROR (_("suppressing non-delimited lines makes sense\n\
 \tonly when operating on fields"));
+    }
 
   set_fields (spec_list_string,
-              ( (operating_mode == field_mode) ? 0 : SETFLD_ERRMSG_USE_POS)
-              | (complement ? SETFLD_COMPLEMENT : 0) );
+              ((byte_mode ? SETFLD_ERRMSG_USE_POS : 0)
+               | (complement ? SETFLD_COMPLEMENT : 0)));
 
   if (!delim_specified)
     delim = '\t';
 
   if (output_delimiter_string == NULL)
     {
-      static char dummy[2];
-      dummy[0] = delim;
-      dummy[1] = '\0';
-      output_delimiter_string = dummy;
+      output_delimiter_default[0] = delim;
+      output_delimiter_string = output_delimiter_default;
       output_delimiter_length = 1;
     }
 
+  void (*cut_stream) (FILE *) = byte_mode ? cut_bytes : cut_fields;
   if (optind == argc)
-    ok = cut_file ("-");
+    ok = cut_file ("-", cut_stream);
   else
     for (ok = true; optind < argc; optind++)
-      ok &= cut_file (argv[optind]);
+      ok &= cut_file (argv[optind], cut_stream);
 
 
   if (have_read_stdin && fclose (stdin) == EOF)
-- 
2.32.0

From 04df9be734c3ce150b7b46088397aa72fcfea929 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 26/43] date: simplify -fsanitize=leak pacification

* src/date.c (main) [lint]: Omit unnecessary cleanup.
Use main_exit, not return.
---
 src/date.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/date.c b/src/date.c
index 18ff22287..0915d7c64 100644
--- a/src/date.c
+++ b/src/date.c
@@ -624,10 +624,7 @@ main (int argc, char **argv)
       ok &= show_date (format_res, when, tz);
     }
 
-  IF_LINT (tzfree (tz));
-  IF_LINT (free (format_copy));
-
-  return ok ? EXIT_SUCCESS : EXIT_FAILURE;
+  main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
 
 /* Display the date and/or time in WHEN according to the format specified
-- 
2.32.0

From 4bc2d7664082cbe3538c55253b9eaf0bb947750b Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 27/43] df: simplify -fsanitize=leak pacification

* src/df.c (print_table, main) [lint]: Omit unnecessary cleanup.
(main): Use main_exit, not return.
---
 src/df.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/src/df.c b/src/df.c
index b803fc73b..7d3207807 100644
--- a/src/df.c
+++ b/src/df.c
@@ -404,14 +404,9 @@ print_table (void)
           /* When ambsalign fails, output unaligned data.  */
           fputs (cell ? cell : table[row][col], stdout);
           free (cell);
-
-          IF_LINT (free (table[row][col]));
         }
       putchar ('\n');
-      IF_LINT (free (table[row]));
     }
-
-  IF_LINT (free (table));
 }
 
 /* Dynamically allocate a struct field_t in COLUMNS, which
@@ -1600,7 +1595,7 @@ field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent',\n\
 int
 main (int argc, char **argv)
 {
-  struct stat *stats IF_LINT ( = 0);
+  struct stat *stats = NULL;
 
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
@@ -1838,7 +1833,7 @@ main (int argc, char **argv)
   get_field_list ();
   get_header ();
 
-  if (optind < argc)
+  if (stats)
     {
       /* Display explicitly requested empty file systems.  */
       show_listed_fs = true;
@@ -1846,8 +1841,6 @@ main (int argc, char **argv)
       for (int i = optind; i < argc; ++i)
         if (argv[i])
           get_entry (argv[i], &stats[i - optind]);
-
-      IF_LINT (free (stats));
     }
   else
     get_all_entries ();
@@ -1869,7 +1862,5 @@ main (int argc, char **argv)
         die (EXIT_FAILURE, 0, _("no file systems processed"));
     }
 
-  IF_LINT (free (columns));
-
-  return exit_status;
+  main_exit (exit_status);
 }
-- 
2.32.0

From b672af465ce808d0608d78c0a2cb7960dd688139 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 28/43] md5sum: remove IF_LINTs

* src/digest.c (digest_check): Remove IF_LINTs that are no longer
needed, as GCC has gotten smarter since 2008.
---
 src/digest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/digest.c b/src/digest.c
index 95782a450..737a8294b 100644
--- a/src/digest.c
+++ b/src/digest.c
@@ -1060,9 +1060,9 @@ digest_check (char const *checkfile_name)
   line_chars_allocated = 0;
   do
     {
-      char *filename IF_LINT ( = NULL);
+      char *filename;
       int binary;
-      unsigned char *hex_digest IF_LINT ( = NULL);
+      unsigned char *hex_digest;
       ssize_t line_length;
 
       ++line_number;
-- 
2.32.0

From 8113a263e9905ee127b0ec73dba9f4ad6467f44b Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 29/43] env: simplify -fsanitize=leak pacification

* src/env.c (unset_envvars): Remove IF_LINT code.
(main): Use main_exit, not return.
---
 src/env.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/src/env.c b/src/env.c
index abcd0a789..f7ef297e7 100644
--- a/src/env.c
+++ b/src/env.c
@@ -184,11 +184,6 @@ unset_envvars (void)
         die (EXIT_CANCELED, errno, _("cannot unset %s"),
              quote (usvars[i]));
     }
-
-  IF_LINT (free (usvars));
-  IF_LINT (usvars = NULL);
-  IF_LINT (usvars_used = 0);
-  IF_LINT (usvars_alloc = 0);
 }
 
 /* Return a pointer to the end of a valid ${VARNAME} string, or NULL.
@@ -904,5 +899,5 @@ main (int argc, char **argv)
   if (exit_status == EXIT_ENOENT && strpbrk (argv[optind], C_ISSPACE_CHARS))
     error (0, 0, _("use -[v]S to pass options in shebang lines"));
 
-  return exit_status;
+  main_exit (exit_status);
 }
-- 
2.32.0

From 1272b700b08486e244bceec6d16768ce6514eea1 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 30/43] expand: remove IF_LINT

* src/expand.c (expand): Remove no-longer-needed IF_LINT.
---
 src/expand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/expand.c b/src/expand.c
index d616997dc..ed78ca81d 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -133,7 +133,7 @@ expand (void)
                 {
                   /* Column the next input tab stop is on.  */
                   uintmax_t next_tab_column;
-                  bool last_tab IF_LINT (=0);
+                  bool last_tab;
 
                   next_tab_column = get_next_tab_column (column, &tab_index,
                                                          &last_tab);
-- 
2.32.0

From 9544789468ead5d7dce5123132629173a80b7848 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 31/43] factor: remove IF_LINT

* src/factor.c (factor_using_squfof) [USE_SQUFOF]:
Use plain assert (...), not IF_LINT (assert (...)).
This code is currently never compiled or executed,
so this is merely a symbolic cleanup.
---
 src/factor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/factor.c b/src/factor.c
index 66ca3878b..66ce28b84 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -2076,7 +2076,7 @@ factor_using_squfof (uintmax_t n1, uintmax_t n0, struct factors *factors)
           div_smallq (q, rem, S + P, Q);
           P1 = S - rem; /* P1 = q*Q - P */
 
-          IF_LINT (assert (q > 0 && Q > 0));
+          assert (q > 0 && Q > 0);
 
 # if STAT_SQUFOF
           q_freq[0]++;
-- 
2.32.0

From 844c3e5e97a79da38c0a4b69610ad425774d7c30 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 32/43] hostname: simplify

* src/hostname.c (sethostname): Provide a substitute on all
platforms, to simplify the mainline code.
(main): Simplify.  Remove an IF_LINT.
Use main_exit rather than return.
---
 src/hostname.c | 41 +++++++++++++++++++----------------------
 1 file changed, 19 insertions(+), 22 deletions(-)

diff --git a/src/hostname.c b/src/hostname.c
index 69e38bb37..e07e98b2b 100644
--- a/src/hostname.c
+++ b/src/hostname.c
@@ -32,18 +32,22 @@
 
 #define AUTHORS proper_name ("Jim Meyering")
 
-#if !defined HAVE_SETHOSTNAME && defined HAVE_SYSINFO && \
-     defined HAVE_SYS_SYSTEMINFO_H
-# include <sys/systeminfo.h>
+#ifndef HAVE_SETHOSTNAME
+# if defined HAVE_SYSINFO && defined HAVE_SYS_SYSTEMINFO_H
+#  include <sys/systeminfo.h>
+# endif
 
 static int
-sethostname (char *name, size_t namelen)
+sethostname (char const *name, size_t namelen)
 {
+# if defined HAVE_SYSINFO && defined HAVE_SYS_SYSTEMINFO_H
   /* Using sysinfo() is the SVR4 mechanism to set a hostname. */
   return (sysinfo (SI_SET_HOSTNAME, name, namelen) < 0 ? -1 : 0);
+# else
+  errno = ENOTSUP;
+  return -1;
+# endif
 }
-
-# define HAVE_SETHOSTNAME 1  /* Now we have it... */
 #endif
 
 void
@@ -84,34 +88,27 @@ main (int argc, char **argv)
                                    Version, true, usage, AUTHORS,
                                    (char const *) NULL);
 
-  if (argc == optind + 1)
+  if (optind + 1 < argc)
+     {
+       error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
+       usage (EXIT_FAILURE);
+     }
+
+  if (optind + 1 == argc)
     {
-#ifdef HAVE_SETHOSTNAME
       /* Set hostname to operand.  */
       char const *name = argv[optind];
       if (sethostname (name, strlen (name)) != 0)
         die (EXIT_FAILURE, errno, _("cannot set name to %s"),
              quote (name));
-#else
-      die (EXIT_FAILURE, 0,
-           _("cannot set hostname; this system lacks the functionality"));
-#endif
     }
-
-  if (argc <= optind)
+  else
     {
       hostname = xgethostname ();
       if (hostname == NULL)
         die (EXIT_FAILURE, errno, _("cannot determine hostname"));
       puts (hostname);
-      IF_LINT (free (hostname));
-    }
-
-  if (optind + 1 < argc)
-    {
-      error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
-      usage (EXIT_FAILURE);
     }
 
-  return EXIT_SUCCESS;
+  main_exit (EXIT_SUCCESS);
 }
-- 
2.32.0

From 010ba6e9ccf4b2c002dad35f0c03acce78a5c671 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 33/43] paste: remove IF_LINT

* src/paste.c (paste_parallel): Remove no-longer-needed IF_LINT.
---
 src/paste.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/paste.c b/src/paste.c
index fafa8bc74..0a8d52535 100644
--- a/src/paste.c
+++ b/src/paste.c
@@ -233,8 +233,8 @@ paste_parallel (size_t nfiles, char **fnamptr)
 
       for (size_t i = 0; i < nfiles && files_open; i++)
         {
-          int chr IF_LINT ( = 0);	/* Input character. */
-          int err IF_LINT ( = 0);	/* Input errno value.  */
+          int chr;			/* Input character. */
+          int err;			/* Input errno value.  */
           bool sometodo = false;	/* Input chars to process.  */
 
           if (fileptr[i])
-- 
2.32.0

From e0b1cde1d3a66626582cab96215d7cf892046540 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 34/43] pinky: simplify -fsanitize=leak pacification

* src/pinky.c (short_pinky): exit instead of freeing.
---
 src/pinky.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/pinky.c b/src/pinky.c
index 52e2af9b1..88862c2f0 100644
--- a/src/pinky.c
+++ b/src/pinky.c
@@ -469,8 +469,7 @@ short_pinky (char const *filename,
     die (EXIT_FAILURE, errno, "%s", quotef (filename));
 
   scan_entries (n_users, utmp_buf, argc_names, argv_names);
-
-  IF_LINT (free (utmp_buf));
+  exit (EXIT_SUCCESS);
 }
 
 static void
-- 
2.32.0

From 5c54c8a86ce6c89e90b91ba104ef33d615141a4e Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 35/43] pr: simplify -fsanitize=leak pacification

* src/pr.c (main): Remove an IF_LINT.
Use main_exit rather than return.
---
 src/pr.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/pr.c b/src/pr.c
index e4771386b..c513038e7 100644
--- a/src/pr.c
+++ b/src/pr.c
@@ -1144,11 +1144,10 @@ main (int argc, char **argv)
     }
 
   cleanup ();
-  IF_LINT (free (file_names));
 
   if (have_read_stdin && fclose (stdin) == EOF)
     die (EXIT_FAILURE, errno, _("standard input"));
-  return failed_opens ? EXIT_FAILURE : EXIT_SUCCESS;
+  main_exit (failed_opens ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
 /* Parse numeric arguments, ensuring MIN <= number <= INT_MAX.  */
-- 
2.32.0

From 8598f3d9632ced255b7cebc784b9cb5986daab58 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 36/43] shred: remove IF_LINT
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/shred.c (dopass): Remove a no-longer-needed IF_LINT.

(read_line): Remove an IF_LINT; no longer needed with
today’s GCC.
---
 src/shred.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/shred.c b/src/shred.c
index e88676380..490fcd07e 100644
--- a/src/shred.c
+++ b/src/shred.c
@@ -422,7 +422,7 @@ dopass (int fd, struct stat const *st, char const *qname, off_t *sizep,
 
   /* Printable previous offset into the file */
   char previous_offset_buf[LONGEST_HUMAN_READABLE + 1];
-  char const *previous_human_offset IF_LINT ( = 0);
+  char const *previous_human_offset;
 
   /* As a performance tweak, avoid direct I/O for small sizes,
      as it's just a performance rather then security consideration,
-- 
2.32.0

From 0f3303df1c4f5230b06b3426924919fa353bd76b Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 37/43] truncate: simplify
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/truncate.c (do_ftruncate): Check != 0 instead of == -1.
Avoid a cast.
(main): Use C99 style decls after statements.
Simplify ‘open’ logic.
---
 src/truncate.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/src/truncate.c b/src/truncate.c
index 918dc305f..cd44edaed 100644
--- a/src/truncate.c
+++ b/src/truncate.c
@@ -187,11 +187,11 @@ do_ftruncate (int fd, char const *fname, off_t ssize, off_t rsize,
   if (nsize < 0)
     nsize = 0;
 
-  if (ftruncate (fd, nsize) == -1)      /* note updates mtime & ctime */
+  if (ftruncate (fd, nsize) != 0)
     {
-      error (0, errno,
-             _("failed to truncate %s at %" PRIdMAX " bytes"), quoteaf (fname),
-             (intmax_t) nsize);
+      intmax_t s = nsize;
+      error (0, errno, _("failed to truncate %s at %"PRIdMAX" bytes"),
+             quoteaf (fname), s);
       return false;
     }
 
@@ -202,12 +202,10 @@ int
 main (int argc, char **argv)
 {
   bool got_size = false;
-  bool errors = false;
   off_t size IF_LINT ( = 0);
   off_t rsize = -1;
   rel_mode_t rel_mode = rm_abs;
-  int c, fd = -1, oflags;
-  char const *fname;
+  int c;
 
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
@@ -353,11 +351,13 @@ main (int argc, char **argv)
         rsize = file_size;
     }
 
-  oflags = O_WRONLY | (no_create ? 0 : O_CREAT) | O_NONBLOCK;
+  int oflags = O_WRONLY | (no_create ? 0 : O_CREAT) | O_NONBLOCK;
+  bool errors = false;
 
-  while ((fname = *argv++) != NULL)
+  for (char const *fname; (fname = *argv); argv++)
     {
-      if ((fd = open (fname, oflags, MODE_RW_UGO)) == -1)
+      int fd = open (fname, oflags, MODE_RW_UGO);
+      if (fd < 0)
         {
           /* 'truncate -s0 -c no-such-file'  shouldn't gen error
              'truncate -s0 no-such-dir/file' should gen ENOENT error
@@ -369,11 +369,8 @@ main (int argc, char **argv)
                      quoteaf (fname));
               errors = true;
             }
-          continue;
         }
-
-
-      if (fd != -1)
+      else
         {
           errors |= !do_ftruncate (fd, fname, size, rsize, rel_mode);
           if (close (fd) != 0)
-- 
2.32.0

From 62c791409cfef508cc5f910f3557d38b3d9d05b2 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 38/43] pr: remove IF_LINT

* src/pr.c (read_line): Remove a no-longer-needed IF_LINT.
---
 src/pr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/pr.c b/src/pr.c
index c513038e7..4c17c0050 100644
--- a/src/pr.c
+++ b/src/pr.c
@@ -2415,7 +2415,7 @@ static bool
 read_line (COLUMN *p)
 {
   int c;
-  int chars IF_LINT ( = 0);
+  int chars;
   int last_input_position;
   int j, k;
   COLUMN *q;
-- 
2.32.0

From 19dd0c6621b5323cfdfe487c52e4500751f684fc Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 39/43] unexpand: remove IF_LINT

* src/unexpand.c (unexpand): Remove a no-longer-needed IF_LINT.
---
 src/unexpand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/unexpand.c b/src/unexpand.c
index 953f92e68..7d6100f6c 100644
--- a/src/unexpand.c
+++ b/src/unexpand.c
@@ -166,7 +166,7 @@ unexpand (void)
 
               if (blank)
                 {
-                  bool last_tab IF_LINT (=0);
+                  bool last_tab;
 
                   next_tab_column = get_next_tab_column (column, &tab_index,
                                                          &last_tab);
-- 
2.32.0

From 7c9d673b8a297d50c8fbea0ec06b488db1284b65 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 40/43] uniq: remove IF_LINT

* src/uniq.c (check_file): Remove a no-longer-needed IF_LINT.
---
 src/uniq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/uniq.c b/src/uniq.c
index 467929872..e5996f0d0 100644
--- a/src/uniq.c
+++ b/src/uniq.c
@@ -354,7 +354,7 @@ check_file (char const *infile, char const *outfile, char delimiter)
   if (output_unique && output_first_repeated && countmode == count_none)
     {
       char *prevfield = NULL;
-      size_t prevlen IF_LINT ( = 0);
+      size_t prevlen;
       bool first_group_printed = false;
 
       while (!feof (stdin))
-- 
2.32.0

From 09fba86d731305fc218ddff44c8ae7558b0f79b1 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 08:42:07 -0800
Subject: [PATCH 41/43] uptime: simplify -fsanitize=leak pacification

* src/uptime.c (uptime): Exit here ...
(main): ... instead of here.
---
 src/uptime.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/uptime.c b/src/uptime.c
index b620885f7..f1cb84a6b 100644
--- a/src/uptime.c
+++ b/src/uptime.c
@@ -186,7 +186,7 @@ uptime (char const *filename, int options)
 
   print_uptime (n_users, utmp_buf);
 
-  IF_LINT (free (utmp_buf));
+  exit (EXIT_SUCCESS);
 }
 
 void
@@ -252,6 +252,4 @@ main (int argc, char **argv)
       error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
       usage (EXIT_FAILURE);
     }
-
-  return EXIT_SUCCESS;
 }
-- 
2.32.0

From dfa833e7d57e5962b83977cd742382caab9f7f40 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 10:20:21 -0800
Subject: [PATCH 42/43] dd: do not access uninitialized
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/dd.c (parse_integer): Avoid undefined behavior
that accesses an uninitialized ‘n’ when e == LONGINT_INVALID.
Return more-accurate error code when INTMAX_MAX < n.
---
 src/dd.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/dd.c b/src/dd.c
index e55f87f14..7360a4973 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -1427,8 +1427,10 @@ static intmax_t
 parse_integer (char const *str, strtol_error *invalid)
 {
   /* Call xstrtoumax, not xstrtoimax, since we don't want to
-     allow strings like "  -0".  */
-  uintmax_t n;
+     allow strings like " -0".  Initialize N to an interminate value;
+     calling code should not rely on this function returning 0
+     when *INVALID represents a non-overflow error.  */
+  uintmax_t n = 0;
   char *suffix;
   strtol_error e = xstrtoumax (str, &suffix, 10, &n, "bcEGkKMPTwYZ0");
 
@@ -1468,7 +1470,7 @@ parse_integer (char const *str, strtol_error *invalid)
 
   if (INTMAX_MAX < n)
     {
-      *invalid = LONGINT_OVERFLOW;
+      *invalid = e | LONGINT_OVERFLOW;
       return INTMAX_MAX;
     }
 
-- 
2.32.0

From d3126e597175c6552e3cec8e7e0c10a57525ba0a Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 31 Jan 2022 10:21:48 -0800
Subject: [PATCH 43/43] maint: pacify gcc -flto -Wmaybe-uninitialized
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* gl/lib/xdectoint.c (__xnumtoint): Tell gcc that ‘error’
does not return here.
* gl/modules/xdectoint (Depends-on): Add stdbool, verify.
---
 gl/lib/xdectoint.c   | 3 +++
 gl/modules/xdectoint | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/gl/lib/xdectoint.c b/gl/lib/xdectoint.c
index 67ec972a1..da53018c0 100644
--- a/gl/lib/xdectoint.c
+++ b/gl/lib/xdectoint.c
@@ -21,10 +21,12 @@
 
 #include <errno.h>
 #include <inttypes.h>
+#include <stdbool.h>
 #include <stdlib.h>
 
 #include "error.h"
 #include "quote.h"
+#include "verify.h"
 #include "xstrtol.h"
 
 /* Parse numeric string N_STR of base BASE, and return the value.
@@ -68,6 +70,7 @@ __xnumtoint (char const *n_str, int base, __xdectoint_t min, __xdectoint_t max,
       /* EINVAL error message is redundant in this context.  */
       error (err_exit ? err_exit : EXIT_FAILURE, errno == EINVAL ? 0 : errno,
              "%s: %s", err, quote (n_str));
+      assume (false);
     }
 
   return tnum;
diff --git a/gl/modules/xdectoint b/gl/modules/xdectoint
index cbd372666..90a278c0b 100644
--- a/gl/modules/xdectoint
+++ b/gl/modules/xdectoint
@@ -11,6 +11,8 @@ Depends-on:
 error
 errno
 quote
+stdbool
+verify
 xstrtoimax
 xstrtoumax
 
-- 
2.32.0

Reply via email to