NationalSecurityAgency/ghidra · error
%s: option `%s' requires an argument\n
Error message
%s: option `%s' requires an argument\n
What it means
A matched long option requires an argument (pfound->has_arg == 1) but optind >= argc — there is no following command-line token to consume. getopt reports the missing argument and returns ':' (if optstring starts with ':') or '?'.
Source
Thrown at GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c:733
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)
optarg = argv[optind++];
else
{
if (opterr)
fprintf (stderr,
_("%s: option `%s' requires an argument\n"),
argv[0], argv[optind - 1]);
nextchar += strlen (nextchar);
optopt = pfound->val;
return optstring[0] == ':' ? ':' : '?';
}
}
nextchar += strlen (nextchar);
if (longind != NULL)
*longind = option_index;
if (pfound->flag)
{
*(pfound->flag) = pfound->val;
return 0;
}
return pfound->val;
}
View on GitHub (pinned to d5f144c24d)
Solutions
- Provide the required argument as the next token
- Use `--option=value` syntax for clarity
- Fix shell quoting around the argument
Example fix
// before ./c++filt --style // after ./c++filt --style gnu-v3
Defensive patterns
Strategy: validation
Validate before calling
// Check that long options requiring an argument have a following value
static int validate_required_long_args(int argc, char *const argv[], const struct option *longopts) {
for (int i = 1; i < argc; i++) {
if (argv[i][0] != '-' || argv[i][1] != '-') continue;
const char *name = argv[i] + 2;
const char *eq = strchr(name, '=');
size_t len = eq ? (size_t)(eq - name) : strlen(name);
for (const struct option *o = longopts; o->name; o++) {
if (strncmp(o->name, name, len) == 0 && strlen(o->name) == len) {
if (o->has_arg == 1 && !eq && i + 1 >= argc) return 0;
break;
}
}
}
return 1;
} Try / catch
int c;
while ((c = getopt_long(argc, argv, optstring, longopts, NULL)) != -1) {
if (c == '?' || c == ':') { exit(EXIT_FAILURE); }
} Prevention
- Always provide a value for argument-requiring long options
- Use --option=value syntax for explicit binding
- Use optstring starting with ':' to distinguish missing-arg from invalid-opt
When it happens
Trigger: User passes `--requirearg` as the last token where that option has has_arg == 1; optind == argc so no next argument exists. opterr is non-zero.
Common situations: Trailing long option that needs a value with none provided; shell quoting that dropped the argument; script logic that conditionally adds the option without its value.
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/f5349f127ec5d6e8.
Report an issue: GitHub.