From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Christopher Li <sparse@chrisli.org>
Cc: Josh Triplett <josh@joshtriplett.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
Linux-Sparse <linux-sparse@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] lib.c: skip --param parameters
Date: Mon, 30 Jun 2014 11:32:45 +0300 [thread overview]
Message-ID: <1404117165.5102.3.camel@smile.fi.intel.com> (raw)
In-Reply-To: <CANeU7QnLad1f4KkLpTGSWB8eD8_La-tACim6rR7DLQ=hggwhOQ@mail.gmail.com>
On Sat, 2014-06-28 at 09:59 -0700, Christopher Li wrote:
> Oops, I just click send before I type up the reply. Here we go again.
>
> On Tue, Jun 17, 2014 at 2:11 AM, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > Very dumb patch to just skip --param allow-store-data-races=0 introduced in
> > newer GCC versions.
> >
> > +static char **handle_param(char *arg, char **next)
> > +{
> > + const char *value = NULL;
> > +
> > + /* For now just skip any '--param=*' or '--param *' */
> > + value = split_value_from_arg(arg, value);
> > + if (!value)
> > + ++next;
> > +
> > + return ++next;
> > +}
>
> I think this is problematic.There are three possible input
> from args:
> 1) "--parm", you need to ++next skip to next arg, which is the value for parm.
> 2) "--parm=x", you don't need to skip to next arg.
> 3) "--parm-with-crap", invalid argument. You don't need to skip next arg.
>
> I think the patch is wrong on case 2) and case 3).
> In case 2), the patch skip two arguments and make next point
> points to out of bound memory.
Hmm... I'd just added test printf to the handle_param() and see if I
print *next, it is either --param or --param=*. So, using return (next +
2) helps, otherwise we end up with the same situation as before patch.
What did I miss?
>
> The split_value_from_arg function is not a good abstraction for this job.
> Its return value can only indicate 2 possible out come.
> Also, returning the default value force the test against the input
> default value. That make the logic a bit complicate.
>
> > struct switches {
> > const char *name;
> > char **(*fn)(char *, char **);
> > @@ -686,13 +698,14 @@ struct switches {
> > static char **handle_long_options(char *arg, char **next)
> > {
> > static struct switches cmd[] = {
> > + { "param", handle_param },
> > { "version", handle_version },
> > { NULL, NULL }
> > };
> > struct switches *s = cmd;
> >
> > while (s->name) {
> > - if (!strcmp(s->name, arg))
> > + if (!strncmp(arg, s->name, strlen(s->name)))
>
> This will allow "--version-with-crap" as valid arguments.
Which was explicitly mentioned in the commit message.
>
> I think we can have one extra member in "struct switch"
> to indicate this option is a prefix rather than a whole word.
> For "parm", it need to set that prefix member to non zero.
No objections about this approach.
> Please let me know if there is a V3 coming.
Apparently you did this on weekend.
--
Andy Shevchenko <andriy.shevchenko@intel.com>
Intel Finland Oy
next prev parent reply other threads:[~2014-06-30 8:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-17 9:11 [PATCH v2 0/2] fix for --param GCC's command line option Andy Shevchenko
2014-06-17 9:11 ` [PATCH v2 1/2] lib.c: introduce split_value_from_arg helper Andy Shevchenko
2014-06-17 9:11 ` [PATCH v2 2/2] lib.c: skip --param parameters Andy Shevchenko
2014-06-28 16:23 ` Christopher Li
2014-06-28 16:59 ` Christopher Li
2014-06-29 7:19 ` Christopher Li
2014-06-29 19:01 ` Christopher Li
2014-06-30 8:32 ` Andy Shevchenko [this message]
2014-06-30 8:51 ` Christopher Li
2014-06-30 8:56 ` Andy Shevchenko
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=1404117165.5102.3.camel@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sparse@vger.kernel.org \
--cc=sparse@chrisli.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 NNTP newsgroup(s).