{"record":{"id":"d3e314c12e2d9f2d","repo":"NationalSecurityAgency/ghidra","slug":"s-option-requires-an-argument-c-n","errorCode":null,"errorMessage":"%s: option requires an argument -- %c\\n","messagePattern":"(.+?): option requires an argument -- %c\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c","lineNumber":956,"sourceCode":"\t      optarg = NULL;\n\t    nextchar = NULL;\n\t  }\n\telse\n\t  {\n\t    /* This is an option that requires an argument.  */\n\t    if (*nextchar != '\\0')\n\t      {\n\t\toptarg = nextchar;\n\t\t/* If we end this ARGV-element by taking the rest as an arg,\n\t\t   we must advance to the next element now.  */\n\t\toptind++;\n\t      }\n\t    else if (optind == argc)\n\t      {\n\t\tif (opterr)\n\t\t  {\n\t\t    /* 1003.2 specifies the format of this message.  */\n\t\t    fprintf (stderr,\n\t\t\t   _(\"%s: option requires an argument -- %c\\n\"),\n\t\t\t   argv[0], c);\n\t\t  }\n\t\toptopt = c;\n\t\tif (optstring[0] == ':')\n\t\t  c = ':';\n\t\telse\n\t\t  c = '?';\n\t      }\n\t    else\n\t      /* We already incremented `optind' once;\n\t\t increment it again when taking next ARGV-elt as argument.  */\n\t      optarg = argv[optind++];\n\t    nextchar = NULL;\n\t  }\n      }\n    return c;\n  }","sourceCodeStart":938,"sourceCodeEnd":974,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c#L938-L974","documentation":"Same 'option requires an argument' condition as error 24 but in the non-reentrant getopt code path (the _getopt_internal wrapper at line 956, not the _r reentrant variant at line 827). A short option marked with ':' in optstring was the last token. The non-reentrant variant sets c but does not return immediately, differing slightly from the reentrant path.","triggerScenarios":"Tool calls the non-reentrant getopt()/getopt_long() rather than getopt_r(); user passes an argument-requiring short option as the final token; optind == argc. opterr is non-zero.","commonSituations":"Same as error 24: trailing option without its value. The distinction is internal to which getopt variant the tool links against.","solutions":["Provide the required argument value after the option","Check that shell quoting preserves the argument","Restructure the command to avoid trailing required-arg options"],"exampleFix":"// before\n./c++filt -s\n// after\n./c++filt -s gnu-v3","handlingStrategy":"validation","validationCode":"// Pre-check: ensure no trailing option-requiring-argument is left without a value\nstatic int no_trailing_missing_arg(int argc, char *const argv[], const char *optstring) {\n    if (argc < 1) return 1;\n    const char *last = argv[argc - 1];\n    if (last[0] == '-' && last[1] != '-') {\n        char last_char = last[strlen(last) - 1];\n        char *pos = strchr(optstring, last_char);\n        if (pos && pos[1] == ':') return 0; // trailing option needs arg\n    }\n    return 1;\n}","typeGuard":null,"tryCatchPattern":"int c;\nwhile ((c = getopt(argc, argv, optstring)) != -1) {\n    if (c == '?' || c == ':') { exit(EXIT_FAILURE); }\n}","preventionTips":["Always supply argument values immediately after options that require them","Use --opt=value syntax to avoid ambiguity","Set optstring[0] = ':' to get ':' return on missing arg for finer control"],"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"}