{"record":{"id":"3ab7182bacfa0810","repo":"NationalSecurityAgency/ghidra","slug":"s-illegal-option-c-n","errorCode":null,"errorMessage":"%s: illegal option -- %c\\n","messagePattern":"(.+?): illegal option -- %c\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c","lineNumber":793,"sourceCode":"    }\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;\n\n    if (temp == NULL || c == ':')\n      {\n\tif (opterr)\n\t  {\n\t    if (posixly_correct)\n\t      /* 1003.2 specifies the format of this message.  */\n\t      fprintf (stderr, _(\"%s: illegal option -- %c\\n\"),\n\t\t       argv[0], c);\n\t    else\n\t      fprintf (stderr, _(\"%s: invalid option -- %c\\n\"),\n\t\t       argv[0], c);\n\t  }\n\toptopt = c;\n\treturn '?';\n      }\n    /* Convenience. Treat POSIX -W foo same as long option --foo */\n    if (temp[0] == 'W' && temp[1] == ';')\n      {\n\tchar *nameend;\n\tconst struct option *p;\n\tconst struct option *pfound = NULL;\n\tint exact = 0;\n\tint ambig = 0;\n\tint indfound = 0;\n\tint option_index;","sourceCodeStart":775,"sourceCodeEnd":811,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c#L775-L811","documentation":"GNU getopt's POSIX-mode diagnostic for an illegal short option. Printed (POSIX 1003.2 format) when posixly_correct is set and a short-option character is not found in optstring or is ':'. getopt then sets optopt and returns '?'. Only the diagnostic differs from the non-POSIX variant; behavior is identical.","triggerScenarios":"POSIXLY_CORRECT (or posixly_correct) is in effect and the user passes a short option letter absent from optstring, or the reserved ':' character as an option.","commonSituations":"Programs run under a POSIXLY_CORRECT=1 environment, or built in an environment that defaults to POSIX mode; option letter typo; optstring not updated for a newly documented flag.","solutions":["Add the missing character to optstring.","Unset POSIXLY_CORRECT if POSIX message formatting is not required (changes the wording, not the return).","Set opterr = 0 to silence the diagnostic and branch on the '?' return / optopt yourself.","Correct the user's typo via the optopt value."],"exampleFix":"// before: optstring omits 'z'; POSIXLY_CORRECT=1 prog -z\nwhile ((c = getopt(argc, argv, \"ab:c\")) != -1) { ... }\n\n// after\nwhile ((c = getopt(argc, argv, \"ab:cz\")) != -1) { ... }","handlingStrategy":"validation","validationCode":"// guard the POSIX-mode illegal-option path\nopterr = 0;\nint c = getopt(argc, argv, \"ab:c\");\nif (c == '?') { reportInvalidOption(optopt); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["If POSIX wording is unwanted, do not set POSIXLY_CORRECT.","Keep optstring authoritative over documented flags.","Handle '?' + optopt rather than relying on stderr text."],"tags":["cli","getopt","argument-parsing","posix","c"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}