{"record":{"id":"c317529f570cb95d","repo":"NationalSecurityAgency/ghidra","slug":"s-option-s-is-ambiguous","errorCode":null,"errorMessage":"%s: option `%s' is ambiguous","messagePattern":"(.+?): option `(.+?)' is ambiguous","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c","lineNumber":687,"sourceCode":"\t\tindfound = option_index;\n\t\texact = 1;\n\t\tbreak;\n\t      }\n\t    else if (pfound == NULL)\n\t      {\n\t\t/* First nonexact match found.  */\n\t\tpfound = p;\n\t\tindfound = option_index;\n\t      }\n\t    else\n\t      /* Second or later nonexact match found.  */\n\t      ambig = 1;\n\t  }\n\n      if (ambig && !exact)\n\t{\n\t  if (opterr)\n\t    fprintf (stderr, _(\"%s: option `%s' is ambiguous\\n\"),\n\t\t     argv[0], argv[optind]);\n\t  nextchar += strlen (nextchar);\n\t  optind++;\n\t  optopt = 0;\n\t  return '?';\n\t}\n\n      if (pfound != NULL)\n\t{\n\t  option_index = indfound;\n\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","sourceCodeStart":669,"sourceCodeEnd":705,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c#L669-L705","documentation":"GNU getopt's long-option matcher: when an abbreviated long option (e.g. --ver for --verbose) matches more than one defined option and no exact match was found, it sets the ambiguous flag and, if opterr is set, prints this message and returns '?'. It is a usage error in the invoking program's command line, surfaced by getopt to stderr.","triggerScenarios":"Passing a long-option prefix that uniquely matches nothing because two or more options share that prefix, with no exact full name given. For example, if both --verbose and --version exist, '--ver' is ambiguous.","commonSituations":"Typing a short abbreviation of a long flag where the program defines multiple options with that prefix; new option added that shadows a previously-unique abbreviation in existing scripts; copy-paste of a flag from a different program version.","solutions":["Spell the long option in full (use --version, not --ver) to avoid prefix ambiguity.","Run the tool's --help to see exact option names and choose a longer unique prefix.","Switch to the single-letter short form if one exists for that option.","Update scripts after adding new options whose names create new prefix collisions."],"exampleFix":"# before (program defines --version and --verbose)\n$ tool --ver\n... option `--ver' is ambiguous\n\n# after - use the full name\n$ tool --version","handlingStrategy":"validation","validationCode":"// Validate the option prefix is unique against the program's known options before invoking\nstd::vector<std::string> matches = optionsStartingWith(prefix);\nif (matches.size() != 1) {\n    fprintf(stderr, \"ambiguous or unknown option prefix: %s\\n\", prefix.c_str());\n    exit(2);\n}","typeGuard":"boolean isUniqueLongPrefix(String prefix, List<String> longOptions) {\n    long matchCount = longOptions.stream().filter(o -> o.startsWith(prefix)).count();\n    return matchCount == 1;\n}","tryCatchPattern":"// getopt prints to stderr and returns '?'; the program usually exits non-zero.\nint rc = run_child({\"tool\", \"--\" + prefix, ...});\nif (rc != 0 && stderr_contains(\"is ambiguous\")) {\n    // re-run with the fully spelled-out option name\n}","preventionTips":["Spell long options in full in scripts to avoid prefix collisions.","After adding a new option, check existing scripts for now-ambiguous abbreviations.","Use short option forms where available for stable scripting.","Document canonical option names and prefer them in tooling."],"tags":["demangler","cli","getopt","arguments","usage"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}