From: Paul Eggert Date: Fri, 16 Jan 2026 06:34:27 +0000 (-0800) Subject: maint: pacify gcc -Wzero-as-null-pointer-constant X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1202fac2dc4d0bd56b0a9e518111319b3c0b153b;p=thirdparty%2Fcoreutils.git maint: pacify gcc -Wzero-as-null-pointer-constant * 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 . --- diff --git a/src/basenc.c b/src/basenc.c index 583c942b83..b5a27e49e2 100644 --- a/src/basenc.c +++ b/src/basenc.c @@ -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}, diff --git a/src/chcon.c b/src/chcon.c index f08711c60c..85a057e693 100644 --- a/src/chcon.c +++ b/src/chcon.c @@ -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; diff --git a/src/copy.c b/src/copy.c index b80b43cc28..661e47aa77 100644 --- a/src/copy.c +++ b/src/copy.c @@ -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; diff --git a/src/env.c b/src/env.c index 67ccaa3dd8..3999225998 100644 --- 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, diff --git a/src/expr.c b/src/expr.c index 7422809b0c..f2b26fcc9e 100644 --- a/src/expr.c +++ b/src/expr.c @@ -533,7 +533,7 @@ nextarg (char const *str) static bool nomoreargs (void) { - return *args == 0; + return !*args; } /* Report missing operand. diff --git a/src/factor.c b/src/factor.c index f6f3aafa4e..f21e37495d 100644 --- a/src/factor.c +++ b/src/factor.c @@ -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. */ diff --git a/src/ls.c b/src/ls.c index b349c74dc9..657d60de1e 100644 --- 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) diff --git a/src/selinux.c b/src/selinux.c index 0a4c0c39e2..c96c2d07d1 100644 --- a/src/selinux.c +++ b/src/selinux.c @@ -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; diff --git a/src/shred.c b/src/shred.c index 7718aa97d8..9979f8df26 100644 --- a/src/shred.c +++ b/src/shred.c @@ -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 */ diff --git a/src/shuf.c b/src/shuf.c index 68d72d538f..e21b38adc0 100644 --- a/src/shuf.c +++ b/src/shuf.c @@ -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 diff --git a/src/tac.c b/src/tac.c index f484aa3774..b893316834 100644 --- 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; diff --git a/src/test.c b/src/test.c index 8c74f38d23..df259f1d32 100644 --- a/src/test.c +++ b/src/test.c @@ -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]) diff --git a/src/uniq.c b/src/uniq.c index cbe2def9ab..4afcf29c87 100644 --- a/src/uniq.c +++ b/src/uniq.c @@ -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;