]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: pacify gcc -Wzero-as-null-pointer-constant
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 16 Jan 2026 06:34:27 +0000 (22:34 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 16 Jan 2026 06:36:16 +0000 (22:36 -0800)
* src/basenc.c (long_options):
* src/chcon.c (change_file_context):
* src/copy.c (is_ancestor):
* src/env.c (build_argv):
* src/expr.c (nomoreargs):
* src/factor.c (mp_no_factors):
* src/ls.c (long_options, main):
* src/selinux.c (defaultcon, restorecon_private):
* src/shred.c (dopass):
* src/shuf.c (long_opts):
* src/tac.c (output):
* src/test.c (term):
* src/uniq.c (check_file): Do not use ‘0’ as a null pointer
constant.  Although it is typically valid C, there are exceptions
(e.g., stdarg) and it a bit cleaner to be consistent.  This patch
uses NULL, not nullptr, as I have second thoughts about nullptr;
see <https://bugs.gnu.org/66221#53>.

13 files changed:
src/basenc.c
src/chcon.c
src/copy.c
src/env.c
src/expr.c
src/factor.c
src/ls.c
src/selinux.c
src/shred.c
src/shuf.c
src/tac.c
src/test.c
src/uniq.c

index 583c942b832db5f4dbd009a5c5c9b45120b0a064..b5a27e49e2dd438359d2145439a0a9a05b90a630 100644 (file)
@@ -74,19 +74,19 @@ enum
 
 static struct option const long_options[] =
 {
-  {"decode", no_argument, 0, 'd'},
-  {"wrap", required_argument, 0, 'w'},
-  {"ignore-garbage", no_argument, 0, 'i'},
+  {"decode", no_argument, NULL, 'd'},
+  {"wrap", required_argument, NULL, 'w'},
+  {"ignore-garbage", no_argument, NULL, 'i'},
 #if BASE_TYPE == 42
-  {"base64",    no_argument, 0, BASE64_OPTION},
-  {"base64url", no_argument, 0, BASE64URL_OPTION},
-  {"base58",    no_argument, 0, BASE58_OPTION},
-  {"base32",    no_argument, 0, BASE32_OPTION},
-  {"base32hex", no_argument, 0, BASE32HEX_OPTION},
-  {"base16",    no_argument, 0, BASE16_OPTION},
-  {"base2msbf", no_argument, 0, BASE2MSBF_OPTION},
-  {"base2lsbf", no_argument, 0, BASE2LSBF_OPTION},
-  {"z85",       no_argument, 0, Z85_OPTION},
+  {"base64",    no_argument, NULL, BASE64_OPTION},
+  {"base64url", no_argument, NULL, BASE64URL_OPTION},
+  {"base58",    no_argument, NULL, BASE58_OPTION},
+  {"base32",    no_argument, NULL, BASE32_OPTION},
+  {"base32hex", no_argument, NULL, BASE32HEX_OPTION},
+  {"base16",    no_argument, NULL, BASE16_OPTION},
+  {"base2msbf", no_argument, NULL, BASE2MSBF_OPTION},
+  {"base2lsbf", no_argument, NULL, BASE2LSBF_OPTION},
+  {"z85",       no_argument, NULL, Z85_OPTION},
 #endif
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
index f08711c60c8c3dc24972e64f0cc77c3d69a901ce..85a057e693f03b28f976c557ad3502b0bff49b7e 100644 (file)
@@ -140,7 +140,7 @@ static int
 change_file_context (int fd, char const *file)
 {
   char *file_context = nullptr;
-  context_t context IF_LINT (= 0);
+  context_t context IF_LINT (= NULL);
   char const * context_string;
   int errors = 0;
 
index b80b43cc288084f833674d2a1427532448c08c51..661e47aa772565424c60a32000225f9576534025 100644 (file)
@@ -245,7 +245,7 @@ ATTRIBUTE_PURE
 static bool
 is_ancestor (const struct stat *sb, const struct dir_list *ancestors)
 {
-  while (ancestors != 0)
+  while (ancestors)
     {
       if (PSAME_INODE (ancestors, sb))
         return true;
index 67ccaa3dd8358907f44a1e9431fa8f3a037df623..3999225998e809519538f42575463d0c9cf81f29 100644 (file)
--- a/src/env.c
+++ b/src/env.c
@@ -358,7 +358,7 @@ build_argv (char const *str, int extra_argc, int *argc)
   ss.half_alloc = extra_argc + 2;
   ss.extra_argc = extra_argc;
   ss.sep = true;
-  ss.argv[ss.argc] = 0;
+  ss.argv[ss.argc] = NULL;
 
   /* In the following loop,
      'break' causes the character 'newc' to be added to *dest,
index 7422809b0cc33c69c829ca824a759ba722909117..f2b26fcc9ee337cbb186e7f4b8f63faaad588f99 100644 (file)
@@ -533,7 +533,7 @@ nextarg (char const *str)
 static bool
 nomoreargs (void)
 {
-  return *args == 0;
+  return !*args;
 }
 
 /* Report missing operand.
index f6f3aafa4e669324d8a1693f90b8ed834c0be417..f21e37495db291d5bbaf70d6d1e2cbabd7880bed 100644 (file)
@@ -659,7 +659,7 @@ static struct mp_factors mp_factor (mpz_t);
 static struct mp_factors
 mp_no_factors (void)
 {
-  return (struct mp_factors) {0,};
+  return (struct mp_factors) {NULL,};
 }
 
 /* Free storage allocated for FACTORS, making it uninitialized.  */
index b349c74dc9a483ed83364a185c29908e1c94bd52..657d60de1eab3f7e6a5fe94e0d1b3b18ebe5a74f 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -917,7 +917,7 @@ static struct option const long_options[] =
   {"color", optional_argument, nullptr, COLOR_OPTION},
   {"hyperlink", optional_argument, nullptr, HYPERLINK_OPTION},
   {"block-size", required_argument, nullptr, BLOCK_SIZE_OPTION},
-  {"context", no_argument, 0, 'Z'},
+  {"context", no_argument, NULL, 'Z'},
   {"author", no_argument, nullptr, AUTHOR_OPTION},
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
@@ -1784,7 +1784,7 @@ main (int argc, char **argv)
       if (pending_dirs)
         dired_outbyte ('\n');
     }
-  else if (n_files <= 1 && pending_dirs && pending_dirs->next == 0)
+  else if (n_files <= 1 && pending_dirs && !pending_dirs->next)
     print_dir_name = false;
 
   while (pending_dirs)
index 0a4c0c39e277f60c4831015dbc0ff4540a715da2..c96c2d07d19379fa6eccc6e5a3a2789911bb3483 100644 (file)
@@ -113,7 +113,7 @@ defaultcon (struct selabel_handle *selabel_handle,
   int rc = -1;
   char *scon_raw = nullptr;
   char *tcon_raw = nullptr;
-  context_t scontext = 0, tcontext = 0;
+  context_t scontext = NULL, tcontext = NULL;
   char const *contype;
   char const *constr;
   char *newpath = nullptr;
@@ -181,7 +181,7 @@ restorecon_private (struct selabel_handle *selabel_handle, char const *path)
   struct stat sb;
   char *scon_raw = nullptr;
   char *tcon_raw = nullptr;
-  context_t scontext = 0, tcontext = 0;
+  context_t scontext = NULL, tcontext = NULL;
   char const *contype;
   char const *constr;
   int fd;
index 7718aa97d8232de92b938c028839218ab6e20867..9979f8df268a9dbfc47dd9b7d29c24372fa78737 100644 (file)
@@ -450,7 +450,7 @@ dopass (int fd, struct stat const *st, char const *qname, off_t *sizep,
     }
   else
     {
-      passname (0, pass_string);
+      passname (NULL, pass_string);
     }
 
   /* Set position if first status update */
index 68d72d538ff2d3a21aab1cf13a2775cb1f672b3f..e21b38adc087f5391418e1365008130bbabe238f 100644 (file)
@@ -103,7 +103,7 @@ static struct option const long_opts[] =
   {"zero-terminated", no_argument, nullptr, 'z'},
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
-  {0, 0, 0, 0},
+  {NULL, 0, NULL, 0},
 };
 
 static void
index f484aa377422562c02e6b8b4e8d8bbfc2d13ed85..b89331683426a3aebd267875e3627f264f93ac02 100644 (file)
--- a/src/tac.c
+++ b/src/tac.c
@@ -152,7 +152,7 @@ output (char const *start, char const *past_end)
   size_t bytes_to_add = past_end - start;
   size_t bytes_available = WRITESIZE - bytes_in_buffer;
 
-  if (start == 0)
+  if (!start)
     {
       fwrite (buffer, 1, bytes_in_buffer, stdout);
       bytes_in_buffer = 0;
index 8c74f38d235d4a59e6518fd599d146a14d913853..df259f1d32f70bde61a10122f01b6e47e84d1b89 100644 (file)
@@ -255,7 +255,7 @@ term (void)
           }
 
       value = posixtest (nargs);
-      if (argv[pos] == 0)
+      if (!argv[pos])
         test_syntax_error (_("%s expected"), quote (")"));
       else
         if (argv[pos][0] != ')' || argv[pos][1])
index cbe2def9abde7017406554970a350c4db64197c0..4afcf29c87e47504ecd537e731fdfdb8e99dd02e 100644 (file)
@@ -357,7 +357,7 @@ check_file (char const *infile, char const *outfile, char delimiter)
       bool first_group_printed = false;
 
       while (!feof (stdin)
-             && readlinebuffer_delim (thisline, stdin, delimiter) != 0)
+             && readlinebuffer_delim (thisline, stdin, delimiter))
         {
           idx_t thislen;
           char *thisfield = find_field (thisline, &thislen);
@@ -388,7 +388,7 @@ check_file (char const *infile, char const *outfile, char delimiter)
     }
   else
     {
-      if (readlinebuffer_delim (prevline, stdin, delimiter) == 0)
+      if (!readlinebuffer_delim (prevline, stdin, delimiter))
         goto closefiles;
 
       idx_t prevlen;
@@ -398,7 +398,7 @@ check_file (char const *infile, char const *outfile, char delimiter)
 
       while (!feof (stdin))
         {
-          if (readlinebuffer_delim (thisline, stdin, delimiter) == 0)
+          if (!readlinebuffer_delim (thisline, stdin, delimiter))
             {
               if (ferror (stdin))
                 goto closefiles;