{"record":{"id":"7153a17f429b327e","repo":"NationalSecurityAgency/ghidra","slug":"s-unrecognized-option-s-n","errorCode":null,"errorMessage":"%s: unrecognized option `--%s'\\n","messagePattern":"(.+?): unrecognized option `--(.+?)'\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c","lineNumber":763,"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":745,"sourceCodeEnd":781,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c#L745-L781","documentation":"In getopt (v2_41), a `--long-option` token matches no entry in longopts and (in getopt_long_only) isn't a valid short option. Identical condition to error 20 but in the v2_41 codebase. opterr is non-zero and the program returns '?' for the token.","triggerScenarios":"User passes `--unknown` where no longopts entry matches; in getopt_long_only, my_index(optstring, *nextchar) is also NULL. opterr is non-zero.","commonSituations":"Typo in a long option name; option from a different version; copy-pasted command from incompatible documentation.","solutions":["Run `--help` to see valid options","Fix the typo","Verify the tool version supports this option"],"exampleFix":"// before\n./c++filt --nouput input\n// after\n./c++filt --no-output input  # or remove the invalid option","handlingStrategy":"validation","validationCode":"// Validate --long-options against the longopts table before calling getopt\nstatic int validate_long_options(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] != '-' || argv[i][2] == '\\0') 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        int found = 0;\n        for (const struct option *o = longopts; o->name; o++) {\n            if (strncmp(o->name, name, len) == 0 && strlen(o->name) == len) { found = 1; break; }\n        }\n        if (!found) { fprintf(stderr, \"Unknown option: --%.*s\\n\", (int)len, name); return 0; }\n    }\n    return 1;\n}","typeGuard":"static int is_known_long_opt(const char *token, const struct option *longopts) {\n    if (!token || token[0] != '-' || token[1] != '-') return 0;\n    const char *name = token + 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 (strlen(o->name) == len && strncmp(o->name, name, len) == 0) return 1;\n    return 0;\n}","tryCatchPattern":"int c;\nwhile ((c = getopt_long(argc, argv, optstring, longopts, NULL)) != -1) {\n    if (c == '?') {\n        fprintf(stderr, \"Usage: %s [options]\\n\", argv[0]);\n        exit(EXIT_FAILURE);\n    }\n}","preventionTips":["Maintain an accurate --help listing of all valid long options","Set opterr to 0 and handle '?' yourself for better error messages","Validate argv 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-14T05:17:29.042Z"}