Linux-rt-users archive mirror
 help / color / mirror / Atom feed
From: John Kacur <jkacur@redhat.com>
To: Anubhav Shelat <ashelat@redhat.com>
Cc: linux-rt-users@vger.kernel.org, kcarcia@redhat.com
Subject: Re: [PATCH v2 2/2] rt-tests: hackbench: properly recognize when integer arguments are negative
Date: Wed, 22 May 2024 13:17:05 -0400 (EDT)	[thread overview]
Message-ID: <cb20ab34-37da-3bf3-c617-9af4eb1dcfa7@redhat.com> (raw)
In-Reply-To: <20240522144347.13281-2-ashelat@redhat.com>



On Wed, 22 May 2024, Anubhav Shelat wrote:

> hackbench is supposed to catch when the user passes
> negative arguments to options -f, -g, -l, and -s.
> 
> Previously hackbench would allow options to accept
> negative arguments, resulting in undefined behavior.
> 
> Now process_options() assigns variables outside of
> the if considiton where they are used. hackbench will
> output a usage message if the user inputs a negative
> argument.
> 
> Signed-off-by: Anubhav Shelat <ashelat@redhat.com>
> ---
>  src/hackbench/hackbench.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/src/hackbench/hackbench.c b/src/hackbench/hackbench.c
> index fec8357bef81..55be325a38df 100644
> --- a/src/hackbench/hackbench.c
> +++ b/src/hackbench/hackbench.c
> @@ -426,7 +426,8 @@ static void process_options(int argc, char *argv[])
>  		}
>  		switch (c) {
>  		case 'f':
> -			if ((num_fds = atoi(optarg)) <= 0) {
> +			num_fds = atoi(optarg);
> +			if (atoi(optarg) <= 0) {
>  				fprintf(stderr, "%s: --fds|-f requires an integer > 0\n", argv[0]);
>  				print_usage_exit(1);
>  			}
> @@ -435,7 +436,8 @@ static void process_options(int argc, char *argv[])
>  			fifo = 1;
>  			break;
>  		case 'g':
> -			if ((num_groups = atoi(optarg)) <= 0) {
> +			num_groups = atoi(optarg);
> +			if (atoi(optarg) <= 0) {
>  				fprintf(stderr, "%s: --groups|-g requires an integer > 0\n", argv[0]);
>  				print_usage_exit(1);
>  			}
> @@ -444,7 +446,8 @@ static void process_options(int argc, char *argv[])
>  			print_usage_exit(0);
>  			break;
>  		case 'l':
> -			if ((loops = atoi(optarg)) <= 0) {
> +			loops = atoi(optarg);
> +			if (atoi(optarg) <= 0) {
>  				fprintf(stderr, "%s: --loops|-l requires an integer > 0\n", argv[0]);
>  				print_usage_exit(1);
>  			}
> @@ -456,7 +459,8 @@ static void process_options(int argc, char *argv[])
>  			use_inet = 1;
>  			break;
>  		case 's':
> -			if ((datasize = atoi(optarg)) <= 0) {
> +			datasize = atoi(optarg);
> +			if (atoi(optarg) <= 0) {
>  				fprintf(stderr, "%s: --datasize|-s requires an integer > 0\n", argv[0]);
>  				print_usage_exit(1);
>  			}
> -- 

Signed-off-by: John Kacur <jkacur@redhat.com>


  reply	other threads:[~2024-05-22 17:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-22 14:43 [PATCH v2 1/2] rt-tests: hackbench: removed extra use of optind Anubhav Shelat
2024-05-22 14:43 ` [PATCH v2 2/2] rt-tests: hackbench: properly recognize when integer arguments are negative Anubhav Shelat
2024-05-22 17:17   ` John Kacur [this message]
2024-05-22 17:17 ` [PATCH v2 1/2] rt-tests: hackbench: removed extra use of optind John Kacur

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cb20ab34-37da-3bf3-c617-9af4eb1dcfa7@redhat.com \
    --to=jkacur@redhat.com \
    --cc=ashelat@redhat.com \
    --cc=kcarcia@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).