{"record":{"id":"8ffaad0168f0aff3","repo":"NationalSecurityAgency/ghidra","slug":"s-option-s-doesn-t-allow-an-argument-n","errorCode":null,"errorMessage":"%s: option `--%s' doesn't allow an argument\\n","messagePattern":"(.+?): option `--(.+?)' doesn't allow an argument\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c","lineNumber":710,"sourceCode":"\t}\n\n      if (pfound != NULL)\n\t{\n\t  option_index = indfound;\n\t  optind++;\n\t  if (*nameend)\n\t    {\n\t      /* Don't test has_arg with >, because some C compilers don't\n\t\t allow it to be used on enums.  */\n\t      if (pfound->has_arg)\n\t\toptarg = nameend + 1;\n\t      else\n\t\t{\n\t\t  if (opterr)\n\t\t    {\n\t\t      if (argv[optind - 1][1] == '-')\n\t\t\t/* --option */\n\t\t\tfprintf (stderr,\n\t\t\t\t _(\"%s: option `--%s' doesn't allow an argument\\n\"),\n\t\t\t\t argv[0], pfound->name);\n\t\t      else\n\t\t\t/* +option or -option */\n\t\t\tfprintf (stderr,\n\t\t\t\t _(\"%s: option `%c%s' doesn't allow an argument\\n\"),\n\t\t\t\t argv[0], argv[optind - 1][0], pfound->name);\n\n\t\t      nextchar += strlen (nextchar);\n\n\t\t      optopt = pfound->val;\n\t\t      return '?';\n\t\t    }\n\t\t}\n\t    }\n\t  else if (pfound->has_arg == 1)\n\t    {\n\t      if (optind < argc)","sourceCodeStart":692,"sourceCodeEnd":728,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c#L692-L728","documentation":"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.","triggerScenarios":"User passes `--flag=value` where `flag` has has_arg == 0 (no_argument). nameend points to the '=' and is non-empty.","commonSituations":"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.","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"],"exampleFix":"// before\n./c++filt --strip-underscore=true\n// after\n./c++filt --strip-underscore","handlingStrategy":"validation","validationCode":"// Verify that a long option accepting an argument is not given one via =value\nstatic int validate_no_arg_attached(int argc, char *const argv[], const struct option *longopts) {\n    for (int i = 1; i < argc; i++) {\n        if (argv[i][0] != '-' || argv[i][1] != '-') continue;\n        char *eq = strchr(argv[i], '=');\n        if (!eq) continue;\n        size_t len = eq - argv[i] - 2;\n        for (const struct option *o = longopts; o->name; o++) {\n            if (strncmp(o->name, argv[i] + 2, len) == 0 && strlen(o->name) == len) {\n                if (o->has_arg == 0) {\n                    fprintf(stderr, \"--%s does not accept an argument\\n\", o->name);\n                    return 0;\n                }\n            }\n        }\n    }\n    return 1;\n}","typeGuard":null,"tryCatchPattern":"int c;\nwhile ((c = getopt_long(argc, argv, optstring, longopts, NULL)) != -1) {\n    if (c == '?') { exit(EXIT_FAILURE); }\n}","preventionTips":["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"],"tags":["cli","getopt","arguments","c"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}