public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Nam Cao <namcao@linutronix.de>
Cc: Clark Williams <williams@redhat.com>,
	John Kacur <jkacur@redhat.com>,
	linux-rt-users@vger.kernel.org
Subject: Re: [PATCH] rt-tests: hackbench: drop incorrect and unnecessary usage of optind
Date: Fri, 5 Apr 2024 10:52:27 +0200	[thread overview]
Message-ID: <20240405085227.1GoglMTY@linutronix.de> (raw)
In-Reply-To: <20240402174659.202695-1-namcao@linutronix.de>

On 2024-04-02 19:46:59 [+0200], Nam Cao wrote:
> Variable "optind" is used as the last argument of getopt_long(). This
> means it "is set to the index of the long option relative to longopts"
> (from man page). NULL check is then performed on argv[optind], which is
> not valid, because in this case, optind is not an index to argv[].
> 
> There is another "optind" which is a global variable, which actually
> holds the index to argv[]. This is likely the actual intention here. By
> locally define another "optind", the "real optind" is shadowed in this
> scope.
> 
> Furthermore, the original optind "is the index of the next element to
> be processed in argv" (from man page), not the index to the current
> element. So doing NULL-check on argv[optind] with the "original optind"
> is also not valid.
> 
> There is no reason to do this NULL-check, since argv[optind] is not even
> read. Only optarg is read, which is never a NULL pointer in this case.
> 
> Delete this incorrect and unnecessary "optind".
> 
> Signed-off-by: Nam Cao <namcao@linutronix.de>

Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Sebastian

  reply	other threads:[~2024-04-05  8:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-02 17:46 [PATCH] rt-tests: hackbench: drop incorrect and unnecessary usage of optind Nam Cao
2024-04-05  8:52 ` Sebastian Andrzej Siewior [this message]
2024-04-05 21:24   ` John Kacur
2024-04-05 21:22 ` 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=20240405085227.1GoglMTY@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=namcao@linutronix.de \
    --cc=williams@redhat.com \
    /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