NationalSecurityAgency/ghidra · error
%s: option `-W %s' doesn't allow an argument
Error message
%s: option `-W %s' doesn't allow an argument
What it means
Using `-W foo`, the option `foo` was found (pfound != NULL) but it takes no argument (pfound->has_arg is false). The user attached an argument via `=value` or ran it directly into the option name (nameend is non-empty). getopt reports the rejection and returns '?'.
Source
Thrown at GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c:892
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
- Remove the argument from the no-argument option
- Verify which options accept values via `--help`
- Use a separate flag if you need to set a value
Example fix
// before ./tool -W strip=true // after ./tool -W strip # strip takes no argument
Defensive patterns
Strategy: validation
Validate before calling
// Check if a -W option accepts an argument before attaching one
static int w_option_accepts_arg(const char *name, const struct option *longopts) {
for (const struct option *o = longopts; o->name; o++) {
if (strcmp(o->name, name) == 0) return o->has_arg != 0;
}
return -1; // unknown option
} Try / catch
int c;
while ((c = getopt_long(argc, argv, optstring, longopts, NULL)) != -1) {
if (c == '?') { exit(EXIT_FAILURE); }
} Prevention
- Check has_arg for each option in the longopts table
- Do not attach =value to no_argument options
- Document which options accept values in --help
When it happens
Trigger: User passes `-W flag=value` or `-W flagvalue` where `flag` has has_arg == 0 (no_argument). nameend points past the option name and is non-empty. opterr is non-zero.
Common situations: Passing a value to a boolean/flag option via -W; misunderstanding which options accept arguments; copy-pasting a command that worked with a different option.
Related errors
- %s: illegal option -- %c
- %s: option `-W %s' is ambiguous
- %s: unrecognized option `--%s'
- %s: unrecognized option `%c%s'
- %s: invalid option -- %c
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/b6f6898a20b5bdfd.
Report an issue: GitHub.