DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Lu, Wenzhuo" <wenzhuo.lu@intel.com>
To: Olivier Matz <olivier.matz@6wind.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>
Subject: [dpdk-dev] CLI parsing issue
Date: Thu, 20 Apr 2017 08:36:38 +0000	[thread overview]
Message-ID: <6A0DE07E22DDAD4C9103DF62FEBC09093B59B248@shsmsx102.ccr.corp.intel.com> (raw)

Hi Olivier,
I met a problem thar the parsing result of CLI is wrong.
I checked this function, cmdline_parse. It will check the CLI instances one by one. Even if an instance is matched, the parsing will not stop for ambiguous check. Seems the following check may change the parsing result of the previous one,
/* fully parsed */
                              tok = match_inst(inst, buf, 0, result.buf, sizeof(result.buf),
                                                            &dyn_tokens);


Is it better to use a temporary validate for match_inst and only store the result when it matches, so the previous result has no chance to be changed? Like bellow,


diff --git a/lib/librte_cmdline/cmdline_parse.c b/lib/librte_cmdline/cmdline_parse.c
index 763c286..663efd1 100644
--- a/lib/librte_cmdline/cmdline_parse.c
+++ b/lib/librte_cmdline/cmdline_parse.c
@@ -259,6 +259,7 @@
                char buf[CMDLINE_PARSE_RESULT_BUFSIZE];
                long double align; /* strong alignment constraint for buf */
        } result;
+       char tmp_buf[CMDLINE_PARSE_RESULT_BUFSIZE];
        cmdline_parse_token_hdr_t *dyn_tokens[CMDLINE_PARSE_DYNAMIC_TOKENS];
        void (*f)(void *, struct cmdline *, void *) = NULL;
        void *data = NULL;
@@ -321,7 +322,7 @@
                debug_printf("INST %d\n", inst_num);

                /* fully parsed */
-               tok = match_inst(inst, buf, 0, result.buf, sizeof(result.buf),
+               tok = match_inst(inst, buf, 0, tmp_buf, sizeof(tmp_buf),
                                 &dyn_tokens);

                if (tok > 0) /* we matched at least one token */
@@ -329,6 +330,8 @@

                else if (!tok) {
                        debug_printf("INST fully parsed\n");
+                       memcpy(result.buf, tmp_buf,
+                              CMDLINE_PARSE_RESULT_BUFSIZE);
                        /* skip spaces */
                        while (isblank2(*curbuf)) {
                                curbuf++;


Best regards
Wenzhuo Lu

             reply	other threads:[~2017-04-20  8:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-20  8:36 Lu, Wenzhuo [this message]
2017-04-20  8:54 ` Olivier MATZ
2017-04-21  1:17   ` Lu, Wenzhuo
2017-04-24  1:49     ` Lu, Wenzhuo
2017-04-24 10:11       ` Olivier Matz
2017-04-25  1:16         ` Lu, Wenzhuo

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=6A0DE07E22DDAD4C9103DF62FEBC09093B59B248@shsmsx102.ccr.corp.intel.com \
    --to=wenzhuo.lu@intel.com \
    --cc=dev@dpdk.org \
    --cc=olivier.matz@6wind.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).