{"record":{"id":"78fee5f816ad6fe4","repo":"NationalSecurityAgency/ghidra","slug":"s-unrecognized-option-c-s","errorCode":null,"errorMessage":"%s: unrecognized option `%c%s'","messagePattern":"(.+?): unrecognized option `%c(.+?)'","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c","lineNumber":768,"sourceCode":"\t  return pfound->val;\n\t}\n\n      /* Can't find it as a long option.  If this is not getopt_long_only,\n\t or the option starts with '--' or is not a valid short\n\t option, then it's an error.\n\t Otherwise interpret it as a short option.  */\n      if (!long_only || argv[optind][1] == '-'\n\t  || my_index (optstring, *nextchar) == NULL)\n\t{\n\t  if (opterr)\n\t    {\n\t      if (argv[optind][1] == '-')\n\t\t/* --option */\n\t\tfprintf (stderr, _(\"%s: unrecognized option `--%s'\\n\"),\n\t\t\t argv[0], nextchar);\n\t      else\n\t\t/* +option or -option */\n\t\tfprintf (stderr, _(\"%s: unrecognized option `%c%s'\\n\"),\n\t\t\t argv[0], argv[optind][0], nextchar);\n\t    }\n\t  nextchar = (char *) \"\";\n\t  optind++;\n\t  optopt = 0;\n\t  return '?';\n\t}\n    }\n\n  /* Look at and handle the next short option-character.  */\n\n  {\n    char c = *nextchar++;\n    char *temp = my_index (optstring, c);\n\n    /* Increment `optind' when we start to process its last character.  */\n    if (*nextchar == '\\0')\n      ++optind;","sourceCodeStart":750,"sourceCodeEnd":786,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c#L750-L786","documentation":"Counterpart to error 20 for the single-dash form. In getopt_long_only, when a token like `-foo` matches no long option AND its first character isn't a valid short option, getopt reports it as unrecognized. The `%c%s` format prints the leading character (usually `-` or `+`) followed by the option text.","triggerScenarios":"getopt_long_only is in use; user passes `-unknown` or `+unknown`; my_index(optstring, *nextchar) returns NULL (first char not a valid short option). opterr must be non-zero.","commonSituations":"Passing a single-dash long-style option that doesn't exist; using getopt_long_only (common in tools like c++filt) and mistyping an option; confusing the option syntax of getopt_long vs getopt_long_only.","solutions":["Check `--help` for valid option names","Use the correct dash convention (-- for long options, - for short)","Fix the typo"],"exampleFix":"// before (getopt_long_only tool)\n./c++filt -nstrip input\n// after\n./c++filt -n input  # or --strip-underscore","handlingStrategy":"validation","validationCode":"// For getopt_long_only, check that single-dash tokens are valid long or short options\nstatic int is_valid_opt_long_only(const char *token, const char *optstring, const struct option *longopts) {\n    if (!token || token[0] != '-' || token[1] == '\\0') return 1; // not an option\n    const char *name = token + 1;\n    for (const struct option *o = longopts; o->name; o++) {\n        if (strcmp(o->name, name) == 0) return 1;\n    }\n    if (strchr(optstring, name[0]) != NULL) return 1;\n    return 0;\n}","typeGuard":"static int is_known_token(const char *tok, const char *optstring, const struct option *longopts) {\n    if (!tok || tok[0] != '-') return 0;\n    const char *name = tok + 1;\n    for (const struct option *o = longopts; o->name; o++)\n        if (strcmp(o->name, name) == 0) return 1;\n    return strchr(optstring, name[0]) != NULL;\n}","tryCatchPattern":"int c;\nwhile ((c = getopt_long_only(argc, argv, optstring, longopts, NULL)) != -1) {\n    if (c == '?') { exit(EXIT_FAILURE); }\n}","preventionTips":["Prefer --double-dash syntax for long options to avoid ambiguity","Document which options are valid in --help","Test CLI invocations with an argument validator in CI"],"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"}