{"record":{"id":"942ba314f4943d5e","repo":"NationalSecurityAgency/ghidra","slug":"s-unrecognized-option-s","errorCode":null,"errorMessage":"%s: unrecognized option `--%s'","messagePattern":"(.+?): unrecognized option `--(.+?)'","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c","lineNumber":764,"sourceCode":"\t    {\n\t      *(pfound->flag) = pfound->val;\n\t      return 0;\n\t    }\n\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);","sourceCodeStart":746,"sourceCodeEnd":782,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c#L746-L782","documentation":"GNU getopt emits this when a `--long-option` token matches no entry in the longopts table. The function walks all long options, finds no exact or prefix match, and (in getopt_long_only) confirms the first character isn't a valid short option. If opterr is non-zero (the default), it prints this diagnostic to stderr and returns '?' for the token.","triggerScenarios":"User passes `--foo` where `foo` is not the `name` field of any struct option in longopts. In getopt_long_only mode, also fires when the token isn't a valid short option either (my_index returns NULL). Requires opterr != 0.","commonSituations":"Typo in a long option name (e.g. `--verison` for `--version`); using an option from a newer/older tool version where it was renamed or removed; copy-pasting a command from docs for a different build.","solutions":["Run the tool with `--help` to list valid long options","Correct the typo in the option name","Confirm the tool version matches the documentation you followed"],"exampleFix":"// before\n./c++filt --verbsoe input.txt\n// after\n./c++filt --verbose input.txt","handlingStrategy":"validation","validationCode":"// Validate that all long options in argv exist in the longopts table\n#include <string.h>\nstatic int is_known_long_opt(const char *token, const struct option *longopts) {\n    const char *name = token + 2; // skip \"--\"\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 != NULL; o++) {\n        if (strncmp(o->name, name, len) == 0 && strlen(o->name) == len)\n            return 1;\n    }\n    return 0;\n}\n// Before calling getopt_long, scan argv for unknown --options\nfor (int i = 1; i < argc; i++) {\n    if (argv[i][0] == '-' && argv[i][1] == '-' && argv[i][2] != '\\0') {\n        if (!is_known_long_opt(argv[i], longopts))\n            fprintf(stderr, \"Warning: unknown option %s\\n\", argv[i]);\n    }\n}","typeGuard":"static int is_valid_long_option(const char *opt, const struct option *longopts) {\n    if (!opt || opt[0] != '-' || opt[1] != '-') return 0;\n    const char *name = opt + 2;\n    for (const struct option *o = longopts; o->name; o++) {\n        if (strcmp(o->name, name) == 0) return 1;\n    }\n    return 0;\n}","tryCatchPattern":"// Check getopt return value for '?'\nint c;\nwhile ((c = getopt_long(argc, argv, optstring, longopts, NULL)) != -1) {\n    if (c == '?') {\n        fprintf(stderr, \"Usage: %s [--known-options] args\\n\", argv[0]);\n        exit(EXIT_FAILURE);\n    }\n    // handle valid options...\n}","preventionTips":["Maintain a --help text that lists all valid long options","Set opterr to 0 and handle '?' yourself for custom error messages","Validate option strings in wrapper scripts before invoking the tool"],"tags":["cli","getopt","arguments","c"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}