incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: cmdopt cleanup
Date Fri, 22 Sep 2006 22:36:11 GMT
Andrew Black wrote:
> Greetings all.
> 
> Attached is a small patch that aims to clean up a few minor bugs in the 
> cmdopt.cpp.  Log below.

This looks good. Just one thing -- can you please follow the
formatting style we discussed (i.e., space between a function
name and the opening parenthesis).

Thanks
Martin

> 
> --Andrew Black
> 
> Log:
>     * cmdopt.cpp (parse_limit_opts): Restrict sub-option values to 
> non-negative integers
>     (eval_options): Ditto for -t, --exit, and --sleep, Fix off-by one 
> error in logic for --ignore and --ulimit, leading to incorrect parsing
> 
> 
> ------------------------------------------------------------------------
> 
> Index: cmdopt.cpp
> ===================================================================
> --- cmdopt.cpp	(revision 449032)
> +++ cmdopt.cpp	(working copy)
> @@ -333,6 +333,10 @@
>  
>                  arg += limits [i].len + 1;
>  
> +                if (!isdigit(*arg)) {
> +                    return 1;
> +                }
> +
>                  char *end;
>                  const long lim = strtol (arg, &end, 10);
>  
> @@ -461,8 +465,10 @@
>              optname = opt_timeout;
>              optarg  = get_short_val (argv, &i);
>              if (optarg) {
> +                if (!isdigit(*optarg))
> +                    bad_value (optname, optarg);
>                  timeout = strtol (optarg, &end, 10);
> -                if (*end || timeout < 0 || errno)
> +                if (*end || errno)
>                      bad_value (optname, optarg);
>              }
>              else
> @@ -512,6 +518,8 @@
>                  optname = opt_exit;
>                  optarg  = get_long_val (argv, &i, sizeof opt_exit - 1);
>                  if (optarg && *optarg) {
> +                    if (!isdigit(*optarg))
> +                        bad_value (optname, optarg);
>                      const long code = strtol (optarg, &end, 10);
>                      if ('\0' == *end && !errno)
>                          exit (code);
> @@ -528,6 +536,8 @@
>                  optname = opt_sleep;
>                  optarg  = get_long_val (argv, &i, sizeof opt_sleep - 1);
>                  if (optarg && *optarg) {
> +                    if (!isdigit(*optarg))
> +                        bad_value (optname, optarg);
>                      const long nsec = strtol (optarg, &end, 10);
>                      if ('\0' == *end && 0 <= nsec && !errno) {
>                          rw_sleep (nsec);
> @@ -549,10 +559,10 @@
>                      }
>                  }
>              }
> -            else if (   sizeof opt_ignore <= arglen
> +            else if (   sizeof opt_ignore - 1 <= arglen
>                       && !memcmp (opt_ignore, argv [i], sizeof opt_ignore - 1))
{
>                  optname = opt_ignore;
> -                optarg  = get_long_val (argv, &i, sizeof opt_ignore);
> +                optarg  = get_long_val (argv, &i, sizeof opt_ignore - 1);
>                  if (optarg && *optarg) {
>                      const long signo = get_signo (optarg);
>                      if (0 <= signo) {
> @@ -563,7 +573,7 @@
>                      }
>                  }
>              }
> -            else if (   sizeof opt_ulimit <= arglen
> +            else if (   sizeof opt_ulimit - 1 <= arglen
>                       && !memcmp (opt_ulimit, argv [i], sizeof opt_ulimit - 1))
{
>                  optname = opt_ulimit;
>                  optarg  = get_long_val (argv, &i, sizeof opt_ulimit - 1);


Mime
View raw message