Harald van Dijk <har...@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.tare...@gmail.com>
Signed-off-by: Herbert Xu <herb...@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 <herb...@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to