{"record":{"id":"f5349f127ec5d6e8","repo":"NationalSecurityAgency/ghidra","slug":"s-option-s-requires-an-argument-n","errorCode":null,"errorMessage":"%s: option `%s' requires an argument\\n","messagePattern":"(.+?): option `(.+?)' requires an argument\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c","lineNumber":733,"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":715,"sourceCodeEnd":751,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c#L715-L751","documentation":"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 '?'.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Provide the required argument as the next token","Use `--option=value` syntax for clarity","Fix shell quoting around the argument"],"exampleFix":"// before\n./c++filt --style\n// after\n./c++filt --style gnu-v3","handlingStrategy":"validation","validationCode":"// Check that long options requiring an argument have a following value\nstatic int validate_required_long_args(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        const char *name = argv[i] + 2;\n        const char *eq = strchr(name, '=');\n        size_t len = eq ? (size_t)(eq - name) : strlen(name);\n        for (const struct option *o = longopts; o->name; o++) {\n            if (strncmp(o->name, name, len) == 0 && strlen(o->name) == len) {\n                if (o->has_arg == 1 && !eq && i + 1 >= argc) return 0;\n                break;\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 == '?' || c == ':') { exit(EXIT_FAILURE); }\n}","preventionTips":["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"],"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"}