From: Harald van Dijk <harald@gigawatt.nl>
To: Luigi Tarenga <luigi.tarenga@gmail.com>, dash@vger.kernel.org
Subject: Re: [BUG] regression in builtin echo
Date: Thu, 1 Sep 2016 22:18:30 +0200 [thread overview]
Message-ID: <3efcd42c-e20b-3506-3d62-69b85c027ef4@gigawatt.nl> (raw)
In-Reply-To: <CAKkO-EgCkv48unwXBjN1JdjSNx3_D1yCZQhde7WJedOFRUDaGg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 783 bytes --]
On 01/09/16 10:13, Luigi Tarenga wrote:
> hi,
> I just find a problem in the dash distributed with arch linux.
> I didn't tested from dash source but the bug can be easily
> checked:
>
> dash 0.5.9-1
>
> $ echo one two three
> one two three
> $
> $ echo -n one two three
> one$
Yikes.
> with -n option it stop after printing one more parameter...
> do you have the same problem or it's caused by a patch in arch?
That's caused by <http://www.spinics.net/lists/dash/msg00942.html>, not
by Arch. It's scary that this has gone totally unnoticed for more than a
year.
While the original code implementing the echo command was overly
complicated, the simplified version does not do the right thing, as you
noticed.
Here's another attempt at a simplified implementation.
> Luigi
[-- Attachment #2: echo.patch --]
[-- Type: text/x-patch, Size: 632 bytes --]
diff --git a/src/bltin/printf.c b/src/bltin/printf.c
index 9673e10..b7b6d68 100644
--- a/src/bltin/printf.c
+++ b/src/bltin/printf.c
@@ -447,16 +447,20 @@ echocmd(int argc, char **argv)
nonl = *++argv ? equal(*argv, "-n") : 0;
argv += nonl;
- do {
- int c;
+ if (*argv) {
+ for (;;) {
+ if (print_escape_str("%s", NULL, NULL, *argv))
+ return 0;
+
+ if (!*++argv)
+ break;
+
+ out1c(' ');
+ }
+ }
- if (likely(*argv))
- nonl += print_escape_str("%s", NULL, NULL, *argv++);
- if (nonl > 0)
- break;
+ if (!nonl)
+ out1c('\n');
- c = *argv ? ' ' : '\n';
- out1c(c);
- } while (*argv);
return 0;
}
next parent reply other threads:[~2016-09-01 22:19 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 ` Harald van Dijk [this message]
2016-09-02 13:14 ` [BUG] regression in builtin echo Herbert Xu
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=3efcd42c-e20b-3506-3d62-69b85c027ef4@gigawatt.nl \
--to=harald@gigawatt.nl \
--cc=dash@vger.kernel.org \
--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).