NationalSecurityAgency/ghidra · error

%s: option `-W %s' doesn't allow an argument\n

Error message

%s: option `-W %s' doesn't allow an argument\n

What it means

GNU getopt_long `-W` diagnostic: the resolved long option does not take an argument (has_arg == 0) but the user supplied one inline, e.g. `-W name=extra` or `-Wname extra`. getopt prints the message, skips the rest of the token, and returns '?'.

Source

Thrown at GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c:891

	      fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
		       argv[0], argv[optind]);
	    nextchar += strlen (nextchar);
	    optind++;
	    return '?';
	  }
	if (pfound != NULL)
	  {
	    option_index = indfound;
	    if (*nameend)
	      {
		/* Don't test has_arg with >, because some C compilers don't
		   allow it to be used on enums.  */
		if (pfound->has_arg)
		  optarg = nameend + 1;
		else
		  {
		    if (opterr)
		      fprintf (stderr, _("\
%s: option `-W %s' doesn't allow an argument\n"),
			       argv[0], pfound->name);

		    nextchar += strlen (nextchar);
		    return '?';
		  }
	      }
	    else if (pfound->has_arg == 1)
	      {
		if (optind < argc)
		  optarg = argv[optind++];
		else
		  {
		    if (opterr)
		      fprintf (stderr,
			       _("%s: option `%s' requires an argument\n"),
			       argv[0], argv[optind - 1]);
		    nextchar += strlen (nextchar);

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Drop the extraneous argument from the `-W` invocation.
  2. If the option should accept an argument, set its has_arg to required_argument / optional_argument in the struct option table.
  3. Switch to the `--flag` form and only attach `=value` for options that take arguments.
  4. Validate option arity against the struct option table before runtime.

Example fix

// before: {"quiet", no_argument, 0, 'q'}; invocation  prog -W quiet=yes
//   -> option `-W quiet' doesn't allow an argument

// after
//   prog -W quiet
// or, if it should take an arg, fix the table:
//   {"quiet", required_argument, 0, 'q'}
Defensive patterns

Strategy: validation

Validate before calling

// verify option arity matches the struct option table before runtime
// ensure options declared no_argument are never invoked with =value

Prevention

When it happens

Trigger: A long option declared with no_argument is invoked via `-W name <text>` where <text> attaches an argument (nameend points past the name).

Common situations: User assumes a flag takes a value; a long option's has_arg was changed from required/optional to none but callers were not updated.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/fe404abc2fe9b2a1. Report an issue: GitHub.