{"record":{"id":"b6f6898a20b5bdfd","repo":"NationalSecurityAgency/ghidra","slug":"s-option-w-s-doesn-t-allow-an-argument","errorCode":null,"errorMessage":"%s: option `-W %s' doesn't allow an argument","messagePattern":"(.+?): option `-W (.+?)' doesn't allow an argument","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c","lineNumber":892,"sourceCode":"\t      fprintf (stderr, _(\"%s: option `-W %s' is ambiguous\\n\"),\n\t\t       argv[0], argv[optind]);\n\t    nextchar += strlen (nextchar);\n\t    optind++;\n\t    return '?';\n\t  }\n\tif (pfound != NULL)\n\t  {\n\t    option_index = indfound;\n\t    if (*nameend)\n\t      {\n\t\t/* Don't test has_arg with >, because some C compilers don't\n\t\t   allow it to be used on enums.  */\n\t\tif (pfound->has_arg)\n\t\t  optarg = nameend + 1;\n\t\telse\n\t\t  {\n\t\t    if (opterr)\n\t\t      fprintf (stderr, _(\"\\\n%s: option `-W %s' doesn't allow an argument\\n\"),\n\t\t\t       argv[0], pfound->name);\n\n\t\t    nextchar += strlen (nextchar);\n\t\t    return '?';\n\t\t  }\n\t      }\n\t    else if (pfound->has_arg == 1)\n\t      {\n\t\tif (optind < argc)\n\t\t  optarg = argv[optind++];\n\t\telse\n\t\t  {\n\t\t    if (opterr)\n\t\t      fprintf (stderr,\n\t\t\t       _(\"%s: option `%s' requires an argument\\n\"),\n\t\t\t       argv[0], argv[optind - 1]);\n\t\t    nextchar += strlen (nextchar);","sourceCodeStart":874,"sourceCodeEnd":910,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c#L874-L910","documentation":"Using `-W foo`, the option `foo` was found (pfound != NULL) but it takes no argument (pfound->has_arg is false). The user attached an argument via `=value` or ran it directly into the option name (nameend is non-empty). getopt reports the rejection and returns '?'.","triggerScenarios":"User passes `-W flag=value` or `-W flagvalue` where `flag` has has_arg == 0 (no_argument). nameend points past the option name and is non-empty. opterr is non-zero.","commonSituations":"Passing a value to a boolean/flag option via -W; misunderstanding which options accept arguments; copy-pasting a command that worked with a different option.","solutions":["Remove the argument from the no-argument option","Verify which options accept values via `--help`","Use a separate flag if you need to set a value"],"exampleFix":"// before\n./tool -W strip=true\n// after\n./tool -W strip  # strip takes no argument","handlingStrategy":"validation","validationCode":"// Check if a -W option accepts an argument before attaching one\nstatic int w_option_accepts_arg(const char *name, const struct option *longopts) {\n    for (const struct option *o = longopts; o->name; o++) {\n        if (strcmp(o->name, name) == 0) return o->has_arg != 0;\n    }\n    return -1; // unknown option\n}","typeGuard":null,"tryCatchPattern":"int c;\nwhile ((c = getopt_long(argc, argv, optstring, longopts, NULL)) != -1) {\n    if (c == '?') { exit(EXIT_FAILURE); }\n}","preventionTips":["Check has_arg for each option in the longopts table","Do not attach =value to no_argument options","Document which options accept values in --help"],"tags":["cli","getopt","arguments","posix","c"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}