{"record":{"id":"fe404abc2fe9b2a1","repo":"NationalSecurityAgency/ghidra","slug":"s-option-w-s-doesn-t-allow-an-argument-n","errorCode":null,"errorMessage":"%s: option `-W %s' doesn't allow an argument\\n","messagePattern":"(.+?): option `-W (.+?)' doesn't allow an argument\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c","lineNumber":891,"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":873,"sourceCodeEnd":909,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c#L873-L909","documentation":"GNU getopt_long `-W` diagnostic: the resolved long option does not take an argument (has_arg == 0) but the user supplied one inline, e.g. `-W name=extra` or `-Wname extra`. getopt prints the message, skips the rest of the token, and returns '?'.","triggerScenarios":"A long option declared with no_argument is invoked via `-W name <text>` where <text> attaches an argument (nameend points past the name).","commonSituations":"User assumes a flag takes a value; a long option's has_arg was changed from required/optional to none but callers were not updated.","solutions":["Drop the extraneous argument from the `-W` invocation.","If the option should accept an argument, set its has_arg to required_argument / optional_argument in the struct option table.","Switch to the `--flag` form and only attach `=value` for options that take arguments.","Validate option arity against the struct option table before runtime."],"exampleFix":"// before: {\"quiet\", no_argument, 0, 'q'}; invocation  prog -W quiet=yes\n//   -> option `-W quiet' doesn't allow an argument\n\n// after\n//   prog -W quiet\n// or, if it should take an arg, fix the table:\n//   {\"quiet\", required_argument, 0, 'q'}","handlingStrategy":"validation","validationCode":"// verify option arity matches the struct option table before runtime\n// ensure options declared no_argument are never invoked with =value","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep has_arg in the struct option table in sync with documentation.","Use --flag form and only attach =value for argument-taking options.","Unit-test each flag's accepted forms."],"tags":["cli","getopt","getopt-long","argument-parsing","c"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}