NationalSecurityAgency/ghidra · error

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

Error message

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

What it means

Same condition as error 36 (option takes no argument but one was attached) but for the single-dash form in getopt_long_only. The leading character is not '-' confirming the +option or single-dash -option form. The `%c%s` format prints the dash character and the option name.

Source

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

	  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)
		optarg = argv[optind++];
	      else
		{
		  if (opterr)
		    fprintf (stderr,

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Remove the attached value from the flag option
  2. Use the --double-dash form with no argument for clarity
  3. Check `--help` for argument requirements

Example fix

// before (getopt_long_only tool)
./c++filt -n=true
// after
./c++filt -n
Defensive patterns

Strategy: validation

Validate before calling

// For getopt_long_only, verify no value is attached to a no_argument option
static int validate_single_dash_no_arg(int argc, char *const argv[], const struct option *longopts) {
    for (int i = 1; i < argc; i++) {
        if (argv[i][0] != '-' || argv[i][1] == '-' || argv[i][1] == '\0') continue;
        char *eq = strchr(argv[i], '=');
        if (!eq) continue;
        size_t len = eq - argv[i] - 1;
        for (const struct option *o = longopts; o->name; o++) {
            if (strncmp(o->name, argv[i] + 1, len) == 0 && strlen(o->name) == len) {
                if (o->has_arg == 0) return 0;
            }
        }
    }
    return 1;
}

Try / catch

int c;
while ((c = getopt_long_only(argc, argv, optstring, longopts, NULL)) != -1) {
    if (c == '?') { exit(EXIT_FAILURE); }
}

Prevention

When it happens

Trigger: getopt_long_only is in use; user passes `-flag=value` where `flag` has has_arg == 0. argv[optind-1][1] != '-'. opterr is non-zero.

Common situations: Using getopt_long_only syntax and attaching a value to a no-argument option; confusing getopt_long and getopt_long_only conventions.

Related errors


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