{"record":{"id":"a79d10eca61ac0e4","repo":"NationalSecurityAgency/ghidra","slug":"s-unrecognized-option-c-s-n","errorCode":null,"errorMessage":"%s: unrecognized option `%c%s'\\n","messagePattern":"(.+?): unrecognized option `%c(.+?)'\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c","lineNumber":767,"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":749,"sourceCodeEnd":785,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c#L749-L785","documentation":"GNU getopt reports an unrecognized option. The `%c%s` form fires for a short-style token (`-x` or `+x`) whose first character is not present in the optstring passed to getopt/getopt_long. The message goes to stderr and getopt returns '?' to the caller; it does not abort. Suppressible by setting opterr = 0.","triggerScenarios":"getopt/getopt_long is invoked with an optstring that does not contain the option letter the user typed (e.g. prog run as `-z` while optstring is \"ab:c\"). Also reached under getopt_long_only when a single-dash token's leading char is neither in optstring nor a unique long-option prefix.","commonSituations":"A flag was added to the usage/help text but never added to the optstring; a typo in the option letter; getopt_long_only ambiguity between a short cluster and a long name.","solutions":["Add the missing option character to the optstring (append ':' if it takes an argument).","Check the offending letter via optopt and correct the typo in the invocation or the optstring.","If the token is intentionally unsupported, set opterr = 0 and handle the returned '?' with a custom message.","With getopt_long_only, rename single-character long options that collide with short-option letters."],"exampleFix":"// before\nwhile ((c = getopt_long(argc, argv, \"ab:c\", lo, &i)) != -1) { ... }\n// invocation: prog -z  ->  unrecognized option `-z'\n\n// after (add 'z', or suppress + handle)\nwhile ((c = getopt_long(argc, argv, \"ab:cz\", lo, &i)) != -1) { ... }","handlingStrategy":"validation","validationCode":"// before getopt, confirm option letters you accept are all in optstring\nconst char *expected = \"ab:cz\";\nif (strchr(expected, userChar) == NULL) { fprintf(stderr, \"bad -%c\\n\", userChar); }\nopterr = 0; // silence builtin; handle '?' yourself","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate usage text and optstring from one source to prevent drift.","Always branch on getopt's '?' return and inspect optopt.","Avoid single-char long-option names when using getopt_long_only."],"tags":["cli","getopt","argument-parsing","c"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}