An enhancement of -p option checking so as to accept only one digital number

Sunzen Wang sunzen@gmail.com
Mon May 18 00:05:00 GMT 2009


Sorry for my late notice.   Actually the same type of issue also
exists for some other options(-s, -x, and partly -S).
It seems better to use a nearly unified solution to enhance their checking.
The first problem is:  is it necessary to do such kind of seemingly
trivial 'enhancement' ?

On Fri, May 15, 2009 at 7:37 PM, Sunzen Wang <sunzen@gmail.com> wrote:
> Let -p option only accept one digital number (between 1-5)
>
> Due to the behavior of atoi(convert the initial portion of the
> specified string),  currently odd optargs with pattern of
> "[digital-number][non-digital]+" (e.g, 1df) are 'sadly' accepted.
> With minimal patch code, the below fix enhances the option checking.
> Is this too protective? IMHO, it seems not.  How about it?
>
> --
> diff --git a/main.cxx b/main.cxx
> index 1ac5dd5..38d2a95 100644
> --- a/main.cxx
> +++ b/main.cxx
> @@ -519,7 +519,7 @@ main (int argc, char * const argv [])
>               usage (s, 1);
>             }
>           s.last_pass = atoi (optarg);
> -          if (s.last_pass < 1 || s.last_pass > 5)
> +          if (strlen(optarg) > 1 || s.last_pass < 1 || s.last_pass > 5)
>             {
>               cerr << "Invalid pass number (should be 1-5)." << endl;
>               usage (s, 1);
> --
>
>
> --
> sunzen
> <<freedom & enjoyment>>
>



-- 
sunzen
<<freedom & enjoyment>>



More information about the Systemtap mailing list