[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [help-gengetopt] a bug, when defining a multiple option with default

From: Lorenzo Bettini
Subject: Re: [help-gengetopt] a bug, when defining a multiple option with default value
Date: Wed, 13 Jun 2007 00:53:08 +0200
User-agent: Icedove (X11/20070329)

Yegor Yefremov wrote:
> Dear list,
> I found a bug, when defining a multiple option with default value. The
> value is assigned but the given variable is not increased:
> else /* set the default value */
>    {
>      if (! args_info->seri_arg && ! args_info->seri_given)
>        {
>          args_info->seri_arg = (char * *) malloc (sizeof (char *));
>          args_info->seri_arg [0] = gengetopt_strdup("/dev/ttyS1");
>          args_info->seri_orig = (char **) malloc (sizeof (char *));
>          args_info->seri_orig [0] = NULL;
>          // here should the variable be increased
>        }
>    }
> // here args_info->seri_given takes 0 value, so I can't access
> args_info->seri_arg
> args_info->seri_given += local_args_info.seri_given;
> local_args_info.seri_given = 0;

this is not actually a bug: the given field says how many times that
option is specified on the command line (or in a configuration file), so
if an option has a default value, then given can be 0 and this tells you
that the user specified no option (if given was incremented even when
the default value is set, then you would have no way to tell whether the
user specified).

You can still access the default value since you know that it's the
first element of the array

NOTICE: you must be aware of default values in a program, so that, in
case of a multiple option, you can safely assume that the first element
of the array argument is always set.

Is this issue clearer?

hope to hear from you soon

Lorenzo Bettini, PhD in Computer Science, DSI, Univ. di Firenze
ICQ# lbetto, 16080134     (GNU/Linux User # 158233)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]