The argp code still uses 0 to denote a null pointer, like in the 1980ies. It makes the code harder to understand than necessary.
2023-09-04 Bruno Haible <br...@clisp.org> argp: Distinguish NULL and '\0' from 0. * lib/argp-pin.c: Include <stddef.h>. (program_invocation_short_name, program_invocation_name): Use NULL instead of 0. * lib/argp-parse.c (convert_options, __argp_parse, __argp_input): Likewise. * lib/argp-fmtstream.c (__argp_make_fmtstream): Likewise. * lib/argp-help.c (make_hol, hol_entry_first_long, hol_find_entry, hol_append, hol_entry_help, argp_doc, _help): Likewise. (hol_usage): Use '\0' instead of 0. diff --git a/lib/argp-fmtstream.c b/lib/argp-fmtstream.c index 7febb76c50..0f6798137b 100644 --- a/lib/argp-fmtstream.c +++ b/lib/argp-fmtstream.c @@ -74,7 +74,7 @@ __argp_make_fmtstream (FILE *stream, if (! fs->buf) { free (fs); - fs = 0; + fs = NULL; } else { diff --git a/lib/argp-help.c b/lib/argp-help.c index 7a277ebf13..15d94993c1 100644 --- a/lib/argp-help.c +++ b/lib/argp-help.c @@ -449,7 +449,7 @@ make_hol (const struct argp *argp, struct hol_cluster *cluster) assert (hol); hol->num_entries = 0; - hol->clusters = 0; + hol->clusters = NULL; if (opts) { @@ -634,7 +634,7 @@ hol_entry_first_long (const struct hol_entry *entry) for (opt = entry->opt, num = entry->num; num > 0; opt++, num--) if (opt->name && ovisible (opt)) return opt->name; - return 0; + return NULL; } /* Returns the entry in HOL with the long option name NAME, or NULL if there is @@ -664,7 +664,7 @@ hol_find_entry (struct hol *hol, const char *name) while (--num_entries > 0); } - return 0; + return NULL; } /* If an entry with the long option NAME occurs in HOL, set its special @@ -945,7 +945,7 @@ hol_append (struct hol *hol, struct hol *more) while (*cl_end) cl_end = &(*cl_end)->next; *cl_end = more->clusters; - more->clusters = 0; + more->clusters = NULL; /* Merge entries. */ if (more->num_entries > 0) @@ -1317,7 +1317,7 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state, { const char *tstr = real->doc ? dgettext (state == NULL ? NULL : state->root_argp->argp_domain, - real->doc) : 0; + real->doc) : NULL; const char *fstr = filter_doc (tstr, real->key, entry->argp, state); if (fstr && *fstr) { @@ -1479,7 +1479,7 @@ hol_usage (struct hol *hol, argp_fmtstream_t stream) entry->argp->argp_domain, &snao_end); if (snao_end > short_no_arg_opts) { - *snao_end++ = 0; + *snao_end++ = '\0'; __argp_fmtstream_printf (stream, " [-%s]", short_no_arg_opts); } @@ -1593,7 +1593,7 @@ argp_doc (const struct argp *argp, const struct argp_state *state, { const char *text; const char *inp_text; - void *input = 0; + void *input = NULL; int anything = 0; size_t inp_text_limit = 0; const char *doc = argp->doc ? dgettext (argp->argp_domain, argp->doc) : NULL; @@ -1681,7 +1681,7 @@ _help (const struct argp *argp, const struct argp_state *state, FILE *stream, unsigned flags, char *name) { int anything = 0; /* Whether we've output anything. */ - struct hol *hol = 0; + struct hol *hol = NULL; argp_fmtstream_t fs; if (! stream) diff --git a/lib/argp-parse.c b/lib/argp-parse.c index dfc4351f9b..a76295feb3 100644 --- a/lib/argp-parse.c +++ b/lib/argp-parse.c @@ -355,9 +355,9 @@ convert_options (const struct argp *argp, group->args_processed = 0; group->parent = parent; group->parent_index = parent_index; - group->input = 0; - group->hook = 0; - group->child_inputs = 0; + group->input = NULL; + group->hook = NULL; + group->child_inputs = NULL; if (children) /* Assign GROUP's CHILD_INPUTS field some space from @@ -373,7 +373,7 @@ convert_options (const struct argp *argp, parent = group++; } else - parent = 0; + parent = NULL; if (children) { @@ -912,7 +912,7 @@ __argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags, (child++)->argp = &argp_default_argp; if (argp_program_version || argp_program_version_hook) (child++)->argp = &argp_version_argp; - child->argp = 0; + child->argp = NULL; argp = top_argp; } @@ -949,7 +949,7 @@ __argp_input (const struct argp *argp, const struct argp_state *state) return group->input; } - return 0; + return NULL; } #ifdef weak_alias weak_alias (__argp_input, _argp_input) diff --git a/lib/argp-pin.c b/lib/argp-pin.c index 76006cb7a1..056e360186 100644 --- a/lib/argp-pin.c +++ b/lib/argp-pin.c @@ -18,11 +18,13 @@ # include <config.h> #endif +#include <stddef.h> + #ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME -char *program_invocation_short_name = 0; +char *program_invocation_short_name = NULL; #endif #ifndef HAVE_PROGRAM_INVOCATION_NAME -char *program_invocation_name = 0; +char *program_invocation_name = NULL; #endif #if (defined HAVE_PROGRAM_INVOCATION_SHORT_NAME \