bad GNU libc argp code In helpcovid git commit e27dd3b123c18300665 we have a stupid bug related to Linux GNU glibc argp program argument parsing.

void
hcv_parse_program_arguments(int &amp;argc, char**argv)
{
  struct argp_state argstate;
  memset (&amp;argstate, 0, sizeof(argstate));
  argstate.input = &amp;hcv_progargs;
  hcv_progargs.hcv_progmagic = HCV_PROGARG_MAGIC;
  static struct argp argparser;
  argparser.options = hcv_progoptions;
  argparser.parser = hcv_parse1opt;
  argparser.args_doc = "*no-positional-arguments*";
  argparser.doc = "github.com/bstarynk/helpcovid"
                  " - a GPLv3+ free software to help organizing"
                  " against Covid19 - NO WARRANTY";
  argparser.children = nullptr;
  argparser.help_filter = nullptr;
  argparser.argp_domain = nullptr;
  if (argp_parse(&amp;argparser, argc, argv, 0, nullptr, nullptr))
    HCV_FATALOUT("failed to parse program arguments to " &lt;&lt; argv[0]);
#warning TODO: complete hcv_parse_program_arguments
} // end hcv_parse_program_arguments


The bug is obvious, but I cannot find it.

At runtime, with the main  function being:

int
main(int argc, char**argv)
{
  hcv_early_initialize(argv[0]);
  hcv_parse_program_arguments(argc, argv);
  HCV_SYSLOGOUT(LOG_NOTICE, "start of " &lt;&lt; argv[0] &lt;&lt; std::endl
                &lt;&lt;  " version:" &lt;&lt; hcv_versionmsg);
  HCV_SYSLOGOUT(LOG_INFO, "normal end of " &lt;&lt; argv[0]);
  return 0;
} // end of main


we observe immediately:

rimski.x86_64 ~/helpcovid 19:12 .0 % ./helpcovid 
** HELPCOVID FATAL! hcv_main.cc:84:: corrupted program arguments
**** FATAL ERROR hcv_main.cc:84
./helpcovid[3684197]: FATAL STOP hcv_main.cc:84 (Success)
zsh: abort (core dumped)  ./helpcovid


happening in

// parse a single program option
static error_t
hcv_parse1opt (int key, char *arg, struct argp_state *state)
{
  /* Get the input argument from argp_parse, which we
     know is a pointer to our arguments structure. */
  struct hcv_progarguments *progargs
    = reinterpret_cast&lt;hcv_progarguments *&gt;(state-&gt;input);
  if (!progargs || progargs-&gt;hcv_progmagic != HCV_PROGARG_MAGIC)
    // this should never happen
    HCV_FATALOUT("corrupted program arguments"); //@@@@@@@@@@@@@@@@@@@
  switch (key)
    {
    default:
      return ARGP_ERR_UNKNOWN;
    }
} // end hcv_parse1opt


The error being at line with //@@@@@@@@@@@@@@@@@@@, file hcv_main.cc line 84. The gdb debugger tells that progargs is a null pointer (and should not be).
I think that the call to argp_parse() in hcv_parse_program_arguments() is missing a pointer to the arguments struct. Looking at the main() function in the canonical Argp Example 3, we see that the argp_parse() function is passed a pointer to struct arguments arguments.

int
main (int argc, char **argv)
{
  struct arguments arguments;

  /* Default values. */
  arguments.silent = 0;
  arguments.verbose = 0;
  arguments.output_file = "-";

  /* Parse our arguments; every option seen by parse_opt will
     be reflected in arguments. */
  argp_parse (&amp;argp, argc, argv, 0, 0, &amp;arguments);

  printf ("ARG1 = %s\nARG2 = %s\nOUTPUT_FILE = %s\n"
          "VERBOSE = %s\nSILENT = %s\n",
          arguments.args[0], arguments.args[1],
          arguments.output_file,
          arguments.verbose ? "yes" : "no",
          arguments.silent ? "yes" : "no");

  exit (0);
}