NationalSecurityAgency/ghidra · error
%s: option `--%s' doesn't allow an argument\n
Error message
%s: option `--%s' doesn't allow an argument\n
What it means
A long option was found (pfound != NULL) but it takes no argument (pfound->has_arg is false). The user attached a value via `--option=value` (nameend is non-empty). The double-dash form is confirmed by argv[optind-1][1] == '-'. opterr is non-zero.
Source
Thrown at GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c:710
}
if (pfound != NULL)
{
option_index = indfound;
optind++;
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)
{
if (argv[optind - 1][1] == '-')
/* --option */
fprintf (stderr,
_("%s: option `--%s' doesn't allow an argument\n"),
argv[0], pfound->name);
else
/* +option or -option */
fprintf (stderr,
_("%s: option `%c%s' doesn't allow an argument\n"),
argv[0], argv[optind - 1][0], pfound->name);
nextchar += strlen (nextchar);
optopt = pfound->val;
return '?';
}
}
}
else if (pfound->has_arg == 1)
{
if (optind < argc)View on GitHub (pinned to d5f144c24d)
Solutions
- Remove the `=value` from the flag option
- Check `--help` to see which options accept arguments
- If you need to set a value, use the correct option that takes one
Example fix
// before ./c++filt --strip-underscore=true // after ./c++filt --strip-underscore
Defensive patterns
Strategy: validation
Validate before calling
// Verify that a long option accepting an argument is not given one via =value
static int validate_no_arg_attached(int argc, char *const argv[], const struct option *longopts) {
for (int i = 1; i < argc; i++) {
if (argv[i][0] != '-' || argv[i][1] != '-') continue;
char *eq = strchr(argv[i], '=');
if (!eq) continue;
size_t len = eq - argv[i] - 2;
for (const struct option *o = longopts; o->name; o++) {
if (strncmp(o->name, argv[i] + 2, len) == 0 && strlen(o->name) == len) {
if (o->has_arg == 0) {
fprintf(stderr, "--%s does not accept an argument\n", o->name);
return 0;
}
}
}
}
return 1;
} Try / catch
int c;
while ((c = getopt_long(argc, argv, optstring, longopts, NULL)) != -1) {
if (c == '?') { exit(EXIT_FAILURE); }
} Prevention
- Do not attach =value to flag (no_argument) options
- Check has_arg field when constructing longopts entries
- Document which options are flags vs value-taking in --help
When it happens
Trigger: User passes `--flag=value` where `flag` has has_arg == 0 (no_argument). nameend points to the '=' and is non-empty.
Common situations: Passing `=value` to a boolean/flag option; copy-pasting from a command for a different option that does accept arguments; misunderstanding which options are flags.
Related errors
- %s: unrecognized option `--%s'
- %s: unrecognized option `%c%s'
- %s: illegal option -- %c
- %s: invalid option -- %c
- %s: option requires an argument -- %c
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/8ffaad0168f0aff3.
Report an issue: GitHub.