This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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>>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]