From: Herbert Xu <herbert@gondor.apana.org.au>
To: Harald van Dijk <harald@gigawatt.nl>
Cc: luigi.tarenga@gmail.com, dash@vger.kernel.org
Subject: Re: [BUG] regression in builtin echo
Date: Fri, 2 Sep 2016 21:14:39 +0800 [thread overview]
Message-ID: <20160902131439.GA12162@gondor.apana.org.au> (raw)
In-Reply-To: <3efcd42c-e20b-3506-3d62-69b85c027ef4@gigawatt.nl>
Harald van Dijk <harald@gigawatt.nl> wrote:
>
> While the original code implementing the echo command was overly
> complicated, the simplified version does not do the right thing, as you
> noticed.
Indeed.
However, we don't need to rewrite the function to fix this.
---8<---
Subject: builtin: Fix echo -n early termination
The commit 7a784244625d5489c0fc779201c349555dc5f8bc ("[BUILTIN]
Simplify echo command") broke echo -n by making it always terminate
after printing the first argument.
This patch fixes this by only terminating when we have reached
the end of the arguments.
Fixes: 7a784244625d ("[BUILTIN] Simplify echo command")
Reported-by: Luigi Tarenga <luigi.tarenga@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
diff --git a/src/bltin/printf.c b/src/bltin/printf.c
index 1112253..a626cee 100644
--- a/src/bltin/printf.c
+++ b/src/bltin/printf.c
@@ -459,7 +459,7 @@ echocmd(int argc, char **argv)
if (likely(*argv))
nonl += print_escape_str("%s", NULL, NULL, *argv++);
- if (nonl > 0)
+ if (likely((nonl + !*argv) > 1))
break;
c = *argv ? ' ' : '\n';
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
next prev parent reply other threads:[~2016-09-02 13:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAKkO-EgCkv48unwXBjN1JdjSNx3_D1yCZQhde7WJedOFRUDaGg@mail.gmail.com>
2016-09-01 20:18 ` [BUG] regression in builtin echo Harald van Dijk
2016-09-02 13:14 ` Herbert Xu [this message]
2016-09-02 14:16 ` Jilles Tjoelker
2016-09-02 14:19 ` Herbert Xu
2016-09-02 15:24 ` Jilles Tjoelker
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=20160902131439.GA12162@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=dash@vger.kernel.org \
--cc=harald@gigawatt.nl \
--cc=luigi.tarenga@gmail.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).