public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
To: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Nicolas Morey-Chaisemartin
	<NMoreyChaisemartin-l3A5Bk7waGM@public.gmane.org>
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH rdma-core 2/5] util: Fix check_snprintf to use __rc__ for local
Date: Fri, 1 Sep 2017 09:00:13 -0600	[thread overview]
Message-ID: <20170901150013.GA21378@obsidianresearch.com> (raw)
In-Reply-To: <20170901045632.GJ10539-U/DQcQFIOTAAJjI8aNfphQ@public.gmane.org>

On Fri, Sep 01, 2017 at 07:56:32AM +0300, Leon Romanovsky wrote:
> On Thu, Aug 31, 2017 at 02:50:56PM -0600, Jason Gunthorpe wrote:
> > To avoid clashing with user variables.
> >
> > Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
> >  util/util.h | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/util/util.h b/util/util.h
> > index cbf0deca2dde7b..30d32ee6b51e24 100644
> > +++ b/util/util.h
> > @@ -8,8 +8,8 @@
> >   * error */
> >  #define check_snprintf(buf, len, fmt, ...)                                     \
> >  	({                                                                     \
> > -		int rc = snprintf(buf, len, fmt, ##__VA_ARGS__);               \
> > -		(rc < len && rc >= 0);                                         \
> > +		int __rc__ = snprintf(buf, len, fmt, ##__VA_ARGS__);           \
> 
> It can't clash, because it is declared in the scope {..} of that define and
> it is local to check_snprintf macro.

This triggers a -Wshadow warning:

 int rc;
 check_snprinf(str, sizeof(str), ..)

And rc is commonly used in callers, so it shouldn't.

Perhaps this addresses all the concerns:

/* Return true if the snprintf succeeded, false if there was truncation or
 * error */
static inline bool __good_snprintf(size_t len, int rc)
{
	return (rc < len && rc >= 0);
}

#define check_snprintf(buf, len, fmt, ...)    \
	__good_snprintf(len, snprintf(buf, len, fmt, ##__VA_ARGS__))

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2017-09-01 15:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-31 20:50 [PATCH rdma-core 0/5] Small fixes for verbs Jason Gunthorpe
     [not found] ` <1504212659-9674-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-08-31 20:50   ` [PATCH rdma-core 1/5] verbs: Remove diagnostic ignored "-Wmissing-prototypes" Jason Gunthorpe
2017-08-31 20:50   ` [PATCH rdma-core 2/5] util: Fix check_snprintf to use __rc__ for local Jason Gunthorpe
     [not found]     ` <1504212659-9674-3-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-09-01  4:56       ` Leon Romanovsky
     [not found]         ` <20170901045632.GJ10539-U/DQcQFIOTAAJjI8aNfphQ@public.gmane.org>
2017-09-01  7:00           ` Nicolas Morey-Chaisemartin
     [not found]             ` <e10f536a-bad3-55b4-f3ef-207404209c89-l3A5Bk7waGM@public.gmane.org>
2017-09-01  9:35               ` Leon Romanovsky
     [not found]                 ` <20170901093553.GK10539-U/DQcQFIOTAAJjI8aNfphQ@public.gmane.org>
2017-09-01  9:46                   ` Nicolas Morey-Chaisemartin
     [not found]                     ` <dfa51066-0d39-5d31-c7e6-b2af1a6089a5-l3A5Bk7waGM@public.gmane.org>
2017-09-01 14:13                       ` Leon Romanovsky
2017-09-01 15:00           ` Jason Gunthorpe [this message]
     [not found]             ` <20170901150013.GA21378-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-09-01 15:13               ` Bart Van Assche
     [not found]                 ` <1504278799.14386.1.camel-Sjgp3cTcYWE@public.gmane.org>
2017-09-01 15:47                   ` Jason Gunthorpe
2017-08-31 20:50   ` [PATCH rdma-core 3/5] verbs: Use ccan list.h instead of open coding lists Jason Gunthorpe
     [not found]     ` <1504212659-9674-4-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-09-01  7:05       ` Nicolas Morey-Chaisemartin
     [not found]         ` <b4255929-e0bc-d779-7190-f38fea24395e-l3A5Bk7waGM@public.gmane.org>
2017-09-02  1:47           ` Jason Gunthorpe
2017-08-31 20:50   ` [PATCH rdma-core 4/5] verbs: Tidy up ibverbs_get_device_list Jason Gunthorpe
     [not found]     ` <1504212659-9674-5-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-09-03 14:03       ` Leon Romanovsky
     [not found]         ` <20170903140351.GO10539-U/DQcQFIOTAAJjI8aNfphQ@public.gmane.org>
2017-09-03 14:48           ` Jason Gunthorpe
     [not found]             ` <20170903144839.GA20230-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-09-03 17:25               ` Leon Romanovsky
2017-08-31 20:50   ` [PATCH rdma-core 5/5] ocrdma: Remove ocrdma_dev_list Jason Gunthorpe
2017-09-04 12:07   ` [PATCH rdma-core 0/5] Small fixes for verbs Yishai Hadas

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=20170901150013.GA21378@obsidianresearch.com \
    --to=jgunthorpe-epgobjl8dl3ta4ec/59zmfatqe2ktcn/@public.gmane.org \
    --cc=NMoreyChaisemartin-l3A5Bk7waGM@public.gmane.org \
    --cc=leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.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