nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Vaibhav Jain <vaibhav@linux.ibm.com>
To: Shivaprasad G Bhat <sbhat@linux.ibm.com>,
	vishal.l.verma@intel.com, nvdimm@lists.linux.dev
Cc: dan.j.williams@intel.com, sbhat@linux.ibm.com
Subject: Re: [PATCH] ndctl: Fix the NDCTL_TIMEOUT environment variable parsing
Date: Wed, 28 Sep 2022 13:19:43 +0530	[thread overview]
Message-ID: <87ill8djl4.fsf@vajain21.in.ibm.com> (raw)
In-Reply-To: <166373424779.231228.12814077203589935658.stgit@LAPTOP-TBQTPII8>

Hi Shiva,

Thanks for fixing this. Minor review comment below:

Shivaprasad G Bhat <sbhat@linux.ibm.com> writes:

> The strtoul(x, y, size) returns empty string on y when the x is "only"
> number with no other suffix strings. The code is checking if !null
> instead of comparing with empty string.
>
> Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
> ---
>  ndctl/lib/libndctl.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
> index ad54f06..b0287e8 100644
> --- a/ndctl/lib/libndctl.c
> +++ b/ndctl/lib/libndctl.c
> @@ -334,7 +334,7 @@ NDCTL_EXPORT int ndctl_new(struct ndctl_ctx **ctx)
>  		char *end;
>  
>  		tmo = strtoul(env, &end, 0);
> -		if (tmo < ULONG_MAX && !end)
> +		if (tmo < ULONG_MAX && strcmp(end, "") == 0)

Using strcmp would be better avoided in new code. Instead you can check
for the valid string to parse in strtoull() with simply checking against
*end == '\0' or !*end.

Quote for STRTOUL(3):

"if *nptr is not '\0' but **endptr is '\0' on return,  the  entire string
is valid."


>  			c->timeout = tmo;
>  		dbg(c, "timeout = %ld\n", tmo);
>  	}
>
>
>
>

-- 
Cheers
~ Vaibhav

      reply	other threads:[~2022-09-28  7:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-21  4:24 [PATCH] ndctl: Fix the NDCTL_TIMEOUT environment variable parsing Shivaprasad G Bhat
2022-09-28  7:49 ` Vaibhav Jain [this message]

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=87ill8djl4.fsf@vajain21.in.ibm.com \
    --to=vaibhav@linux.ibm.com \
    --cc=dan.j.williams@intel.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=sbhat@linux.ibm.com \
    --cc=vishal.l.verma@intel.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;
as well as URLs for NNTP newsgroup(s).