{"record":{"id":"78f496dc7826a2a3","repo":"NationalSecurityAgency/ghidra","slug":"s-option-c-s-doesn-t-allow-an-argument-n","errorCode":null,"errorMessage":"%s: option `%c%s' doesn't allow an argument\\n","messagePattern":"(.+?): option `%c(.+?)' 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":715,"sourceCode":"\t  optind++;\n\t  if (*nameend)\n\t    {\n\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      if (pfound->has_arg)\n\t\toptarg = nameend + 1;\n\t      else\n\t\t{\n\t\t  if (opterr)\n\t\t    {\n\t\t      if (argv[optind - 1][1] == '-')\n\t\t\t/* --option */\n\t\t\tfprintf (stderr,\n\t\t\t\t _(\"%s: option `--%s' doesn't allow an argument\\n\"),\n\t\t\t\t argv[0], pfound->name);\n\t\t      else\n\t\t\t/* +option or -option */\n\t\t\tfprintf (stderr,\n\t\t\t\t _(\"%s: option `%c%s' doesn't allow an argument\\n\"),\n\t\t\t\t argv[0], argv[optind - 1][0], pfound->name);\n\n\t\t      nextchar += strlen (nextchar);\n\n\t\t      optopt = pfound->val;\n\t\t      return '?';\n\t\t    }\n\t\t}\n\t    }\n\t  else if (pfound->has_arg == 1)\n\t    {\n\t      if (optind < argc)\n\t\toptarg = argv[optind++];\n\t      else\n\t\t{\n\t\t  if (opterr)\n\t\t    fprintf (stderr,","sourceCodeStart":697,"sourceCodeEnd":733,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c#L697-L733","documentation":"Same condition as error 36 (option takes no argument but one was attached) but for the single-dash form in getopt_long_only. The leading character is not '-' confirming the +option or single-dash -option form. The `%c%s` format prints the dash character and the option name.","triggerScenarios":"getopt_long_only is in use; user passes `-flag=value` where `flag` has has_arg == 0. argv[optind-1][1] != '-'. opterr is non-zero.","commonSituations":"Using getopt_long_only syntax and attaching a value to a no-argument option; confusing getopt_long and getopt_long_only conventions.","solutions":["Remove the attached value from the flag option","Use the --double-dash form with no argument for clarity","Check `--help` for argument requirements"],"exampleFix":"// before (getopt_long_only tool)\n./c++filt -n=true\n// after\n./c++filt -n","handlingStrategy":"validation","validationCode":"// For getopt_long_only, verify no value is attached to a no_argument option\nstatic int validate_single_dash_no_arg(int argc, char *const argv[], const struct option *longopts) {\n    for (int i = 1; i < argc; i++) {\n        if (argv[i][0] != '-' || argv[i][1] == '-' || argv[i][1] == '\\0') continue;\n        char *eq = strchr(argv[i], '=');\n        if (!eq) continue;\n        size_t len = eq - argv[i] - 1;\n        for (const struct option *o = longopts; o->name; o++) {\n            if (strncmp(o->name, argv[i] + 1, len) == 0 && strlen(o->name) == len) {\n                if (o->has_arg == 0) return 0;\n            }\n        }\n    }\n    return 1;\n}","typeGuard":null,"tryCatchPattern":"int c;\nwhile ((c = getopt_long_only(argc, argv, optstring, longopts, NULL)) != -1) {\n    if (c == '?') { exit(EXIT_FAILURE); }\n}","preventionTips":["Use --double-dash for long options to avoid getopt_long_only confusion","Never attach =value to flag options","Check has_arg semantics before writing CLI wrapper scripts"],"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"}