From: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Nicolas Morey-Chaisemartin
<NMoreyChaisemartin-l3A5Bk7waGM@public.gmane.org>
Cc: Jason Gunthorpe
<jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>,
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 17:13:55 +0300 [thread overview]
Message-ID: <20170901141355.GL10539@mtr-leonro.local> (raw)
In-Reply-To: <dfa51066-0d39-5d31-c7e6-b2af1a6089a5-l3A5Bk7waGM@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 2424 bytes --]
On Fri, Sep 01, 2017 at 11:46:02AM +0200, Nicolas Morey-Chaisemartin wrote:
>
>
> Le 01/09/2017 à 11:35, Leon Romanovsky a écrit :
> > On Fri, Sep 01, 2017 at 09:00:01AM +0200, Nicolas Morey-Chaisemartin wrote:
> >>
> >> Le 01/09/2017 à 06:56, Leon Romanovsky a écrit :
> >>> 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
> >>>> --- a/util/util.h
> >>>> +++ 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.
> >> It does if any of the va-args is called rc.
> >> This is "valid" C although not sure what printfs does print here (probably random stack value)
> >> {
> >> int i = printf("i = %d\n", i);
> >> }
> > So how does this rename solve the issue?
> > Now, we can clash with __rc__ variable.
> >
> > Thanks
>
> There is no safe way to handle that. It can be detected with -Wshadow though.
> But rc is quite a common name (39 definitions in the code base), __rc__ much less (unused... yet)
Or commit message should reflect that it is not fix, but attempt to
reduce name collision, or the patch should provide real fix. For
example, create inline function and convert all 5 callers to use it
without ##__VA_ARGS__.
>
>
> If you want some real fun, try writing macros with local variables that can be called recursively ;)
>
> Nicolas
>
> --
> 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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2017-09-01 14:13 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 [this message]
2017-09-01 15:00 ` Jason Gunthorpe
[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=20170901141355.GL10539@mtr-leonro.local \
--to=leon-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
--cc=NMoreyChaisemartin-l3A5Bk7waGM@public.gmane.org \
--cc=jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@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