{"record":{"id":"b8c09759adea5295","repo":"NationalSecurityAgency/ghidra","slug":"s-option-s-is-ambiguous-n","errorCode":null,"errorMessage":"%s: option `%s' is ambiguous\\n","messagePattern":"(.+?): option `(.+?)' is ambiguous\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c","lineNumber":686,"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":668,"sourceCodeEnd":704,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c#L668-L704","documentation":"In getopt (v2_41), a long-option token is a prefix of two or more entries in the longopts table and no exact match exists. getopt sets ambig on the second prefix match and, combined with !exact, reports the ambiguity and returns '?'.","triggerScenarios":"User passes `--pre` and longopts contains both `prefix` and `preview`; no entry named exactly `pre`. opterr is non-zero.","commonSituations":"Abbreviating long options in scripts with prefixes that later become ambiguous when new options are added; using a short abbreviation that worked in an older version.","solutions":["Spell out the full option name","Use a longer unambiguous prefix","Check `--help` for option names"],"exampleFix":"// before\n./c++filt --ver input\n// after\n./c++filt --verbose input","handlingStrategy":"validation","validationCode":"// Check if a long-option prefix is ambiguous before passing to getopt\nstatic int is_unique_prefix(const char *prefix, const struct option *longopts) {\n    int matches = 0;\n    size_t plen = strlen(prefix);\n    for (const struct option *o = longopts; o->name; o++) {\n        if (strncmp(o->name, prefix, plen) == 0) matches++;\n    }\n    return matches == 1;\n}","typeGuard":null,"tryCatchPattern":"int c;\nwhile ((c = getopt_long(argc, argv, optstring, longopts, NULL)) != -1) {\n    if (c == '?') { exit(EXIT_FAILURE); }\n}","preventionTips":["Spell out full option names in scripts to avoid prefix ambiguity","When adding new long options, check for new prefix collisions","Use --option=value syntax for maximum clarity"],"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"}