delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/01/13/04:45:45

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Tue, 13 Jan 2009 10:44:48 +0100
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: bug in cygwin's gcc/g++ getopt_long(): erroneous "ambiguous option"
Message-ID: <20090113094448.GU400@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <b2c39fcb0901122149j1f3057adhaa600ea21fe7156c AT mail DOT gmail DOT com>
MIME-Version: 1.0
In-Reply-To: <b2c39fcb0901122149j1f3057adhaa600ea21fe7156c@mail.gmail.com>
User-Agent: Mutt/1.5.17 (2007-11-01)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Jan 13 00:49, Dan Tsafrir wrote:
> Hi,
> 
> When given certain long options, Cygwin's getopt_long() function
> erroneously fails on "ambiguous option". The short program below
> illustrates the problem: getopt_long() wrongfully reports the "--xy"
> option as ambiguous.
> 
> Strangely, if flipping the order of the 2nd and 3rd entries in the
> options-array (by compiling the program with -DNO_BUG) the bug goes
> away, clearly demonstrating inconsistent Cygwin/getopt_long behavior.
> [...]
> #include <stdio.h>
> #include <getopt.h>
> 
> const struct option lopts[] = {
> #ifdef NO_BUG
>     {"xy1" , required_argument, NULL, 'a' },
>     {"xy"  , required_argument, NULL, 'b' },
>     {"xy2" , required_argument, NULL, 'c' },
>     {NULL  , 0                , NULL,  0  },
> #else /* swapping order of 2nd and 3rd entries generates the bug */
>     {"xy1" , required_argument, NULL, 'a' },
>     {"xy2" , required_argument, NULL, 'c' },
>     {"xy"  , required_argument, NULL, 'b' },
>     {NULL  , 0                , NULL,  0  },
> #endif
> };
> 
> int main()
> {
>     const char* argv[] = {"./a", "--xy=1", NULL};
>     int argc = 2;
>     int index, c;
> 
>     // if NO_BUG defined, will print: "got opt=b" [OK]
>     // otherwise: "a: ambiguous option -- xy" [BUG]
>     if( (c = getopt_long(argc, (char**)argv, "A:B:C", lopts, &index)) != EOF )
>         printf("got opt=%c\n", c);
> 
>     return 0;
> }

This appears to be a bug in the upstream version of getopt we're
using in Cygwin, which is the latest version from OpenBSD.  I'm
looking into creating a patch for Cygwin 1.7.


Thanks for the report,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019