From: Mike Frysinger <vapier@gentoo.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 1/4] Add run_command_list() to run a list of commands
Date: Sun, 8 Apr 2012 04:39:07 -0400 [thread overview]
Message-ID: <201204080439.09360.vapier@gentoo.org> (raw)
In-Reply-To: <CAPnjgZ1sighZJAgvLmZD+0DHtHD_rBmXu9oXm_inD=Xb1w649A@mail.gmail.com>
On Wednesday 04 April 2012 03:12:27 Simon Glass wrote:
> On Sun, Apr 1, 2012 at 12:48 PM, Mike Frysinger wrote:
> > On Saturday 31 March 2012 03:30:55 Simon Glass wrote:
> >> --- a/common/cmd_pxe.c
> >> +++ b/common/cmd_pxe.c
> >>
> >> +int run_command_list(const char *cmd, int len, int flag)
> >> +{
> >> + int need_buff = 1;
> >> + char *buff = (char *)cmd; /* cast away const */
> >> + int rcode = 0;
> >> +
> >> + if (len == -1) {
> >> + len = strlen(cmd);
> >> +#ifdef CONFIG_SYS_HUSH_PARSER
> >> + /* hush will never change our string */
> >> + need_buff = 0;
> >> +#else
> >> + /* the built-in parser will change our string if it sees
> >> \n */ + need_buff = strchr(cmd, '\n') != NULL;
> >> +#endif
> >> + }
> >
> > we have memchr(), so you should be able to split the len==-1 and the
> > need_buff logic into two sep steps
>
> Are you saying that we should do this check if len is not -1 also?
>
> I am only doing it when len is not specified, since if a length is
> provided we must allocate. This is used by the source command, which
> does not necessary have a nul-terminated string.
looks to me like it should be:
int need_buff;
if (len == -1)
len = strlen(cmd);
#ifdef CONFIG_SYS_HUSH_PARSER
need_buff = 0;
#else
need_buff = memchr(cmd, '\n', len) != NULL;
#endif
if (need_buff) {
...
}
> > also, should you handle the case where '\n' is the very last char ? or
> > not bother ?
>
> Do you mean not allocate in that case? I don't think it is a common
> situation is it?
i don't know how commands get passed down (as i've never poked that area
before) which is why i'm asking
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120408/a54f35ff/attachment.pgp>
next prev parent reply other threads:[~2012-04-08 8:39 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-31 7:30 [U-Boot] [PATCH v3 1/4] Add run_command_list() to run a list of commands Simon Glass
2012-03-31 7:30 ` [U-Boot] [PATCH v3 2/4] Allow newlines within command environment vars Simon Glass
2012-08-09 20:06 ` Wolfgang Denk
2012-03-31 7:30 ` [U-Boot] [PATCH v3 3/4] sandbox: Use the new run_command() Simon Glass
2012-04-01 19:53 ` Mike Frysinger
2012-04-23 20:54 ` Wolfgang Denk
2012-03-31 7:30 ` [U-Boot] [PATCH v3 4/4] sandbox: Add basic test for command execution Simon Glass
2012-04-01 19:53 ` Mike Frysinger
2012-04-04 7:18 ` Simon Glass
2012-04-08 8:40 ` Mike Frysinger
2012-08-09 20:06 ` Wolfgang Denk
2012-04-01 19:48 ` [U-Boot] [PATCH v3 1/4] Add run_command_list() to run a list of commands Mike Frysinger
2012-04-04 7:12 ` Simon Glass
2012-04-08 8:39 ` Mike Frysinger [this message]
2012-04-09 4:46 ` Simon Glass
2012-08-09 20:06 ` Wolfgang Denk
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=201204080439.09360.vapier@gentoo.org \
--to=vapier@gentoo.org \
--cc=u-boot@lists.denx.de \
/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