{"record":{"id":"325577d330643aeb","repo":"NationalSecurityAgency/ghidra","slug":"s-invalid-option-c","errorCode":null,"errorMessage":"%s: invalid option -- %c","messagePattern":"(.+?): invalid option -- %c","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c","lineNumber":797,"sourceCode":"\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;\n\n\t/* This is an option that requires an argument.  */\n\tif (*nextchar != '\\0')","sourceCodeStart":779,"sourceCodeEnd":815,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c#L779-L815","documentation":"Same underlying condition as error 22 (short option character not in optstring), but in non-POSIX mode the wording is 'invalid option' instead of 'illegal option'. This is the default wording when posixly_correct is false.","triggerScenarios":"User passes `-X` where `X` is not in optstring; posixly_correct is false; opterr is non-zero. Also fires when c is ':' but ':' isn't a leading character in optstring.","commonSituations":"Passing an unsupported short option in the default (non-POSIX) environment; typo in a short option flag; using options from a different version of the tool.","solutions":["Remove or correct the unsupported short option","Check `tool --help` for valid flags","Verify the option exists in this build/version"],"exampleFix":"// before\n./c++filt -Z\n// after\n./c++filt -n","handlingStrategy":"validation","validationCode":"// Verify each short-option flag char is present in the optstring\nstatic int validate_short_flags(int argc, char *const argv[], const char *optstring) {\n    for (int i = 1; i < argc && argv[i][0] == '-' && argv[i][1] != '-'; i++) {\n        for (const char *p = argv[i] + 1; *p && *p != '='; p++) {\n            if (strchr(optstring, *p) == NULL) {\n                fprintf(stderr, \"Invalid option: -%c\\n\", *p);\n                return 0;\n            }\n        }\n    }\n    return 1;\n}","typeGuard":"static int is_valid_short_opt_char(char c, const char *optstring) {\n    return c != ':' && strchr(optstring, c) != NULL;\n}","tryCatchPattern":"int c;\nwhile ((c = getopt(argc, argv, optstring)) != -1) {\n    if (c == '?') { fprintf(stderr, \"Usage: %s [options]\\n\", argv[0]); exit(EXIT_FAILURE); }\n}","preventionTips":["Keep an up-to-date --help listing of valid short options","Set opterr to 0 for programmatic error handling","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"}