{"record":{"id":"e340f622ab47b0ff","repo":"NationalSecurityAgency/ghidra","slug":"s-option-s-requires-an-argument","errorCode":null,"errorMessage":"%s: option `%s' requires an argument","messagePattern":"(.+?): option `(.+?)' requires an argument","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c","lineNumber":734,"sourceCode":"\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)\n\t\toptarg = argv[optind++];\n\t      else\n\t\t{\n\t\t  if (opterr)\n\t\t    fprintf (stderr,\n\t\t\t   _(\"%s: option `%s' requires an argument\\n\"),\n\t\t\t   argv[0], argv[optind - 1]);\n\t\t  nextchar += strlen (nextchar);\n\t\t  optopt = pfound->val;\n\t\t  return optstring[0] == ':' ? ':' : '?';\n\t\t}\n\t    }\n\t  nextchar += strlen (nextchar);\n\t  if (longind != NULL)\n\t    *longind = option_index;\n\t  if (pfound->flag)\n\t    {\n\t      *(pfound->flag) = pfound->val;\n\t      return 0;\n\t    }\n\t  return pfound->val;\n\t}\n","sourceCodeStart":716,"sourceCodeEnd":752,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c#L716-L752","documentation":"GNU getopt long-option path: the matched option has has_arg == 1 (required_argument) but no argument is available (optind >= argc, i.e. the option was last on the command line with no following token and no attached =value). With opterr set, getopt prints this and returns optstring[0]==':' ? ':' : '?'. It is a missing-required-argument usage error.","triggerScenarios":"Specifying a long option that requires an argument but providing none - e.g. '--style' as the last token with no following value and no '=value'. getopt looks for the next argv element, finds none, and reports the requirement.","commonSituations":"Forgetting the value for an option that needs one (-o/--output with no filename); the value being swallowed by shell quoting/word-splitting so getopt sees the option as last; a script conditionally appending the flag but not its value; trailing-option positioned where the value is parsed as another flag.","solutions":["Provide the required argument: --style=gnu or --style gnu.","Check --help to confirm which options require arguments and their expected values.","Quote/escape the argument so the shell passes it as one token that getopt can consume.","Review the script's conditional flag-building to ensure value and flag are appended together."],"exampleFix":"# before\n$ tool --style\n... option `--style' requires an argument\n\n# after\n$ tool --style gnu   # or --style=gnu","handlingStrategy":"validation","validationCode":"// Ensure required-argument options always receive a value\nif (optionRequiresArg(name) && value == null) {\n    throw new IllegalArgumentException(\"Option \" + name + \" requires an argument\");\n}","typeGuard":"boolean isCompleteInvocation(String name, String value, Set<String> requiredArgFlags) {\n    return !requiredArgFlags.contains(name) || value != null;\n}","tryCatchPattern":"int rc = run_child({\"tool\", \"--\" + name});\nif (rc != 0 && stderr_contains(\"requires an argument\")) {\n    // prompt for or supply the missing value, then re-run\n}","preventionTips":["Consult --help to learn which options require arguments.","When conditionally appending a flag, always append its value in the same branch.","Quote the argument so the shell delivers it as one token for getopt to consume.","Validate assembled argument lists against the option spec before invoking the tool."],"tags":["demangler","cli","getopt","arguments","usage"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}