From patchwork Fri Sep 2 13:14:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 9311017 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 51A8A60760 for ; Fri, 2 Sep 2016 13:14:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 434A0297A0 for ; Fri, 2 Sep 2016 13:14:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37F2F297A9; Fri, 2 Sep 2016 13:14:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.4 required=2.0 tests=BAYES_00,FAKE_REPLY_C, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E58B7297A0 for ; Fri, 2 Sep 2016 13:14:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752389AbcIBNOt (ORCPT ); Fri, 2 Sep 2016 09:14:49 -0400 Received: from helcar.hengli.com.au ([209.40.204.226]:50825 "EHLO helcar.hengli.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751074AbcIBNOs (ORCPT ); Fri, 2 Sep 2016 09:14:48 -0400 Received: from gondolin.me.apana.org.au ([192.168.0.6]) by norbury.hengli.com.au with esmtp (Exim 4.80 #3 (Debian)) id 1bfoIv-0003i8-18; Fri, 02 Sep 2016 23:14:45 +1000 Received: from herbert by gondolin.me.apana.org.au with local (Exim 4.80) (envelope-from ) id 1bfoIq-0003AZ-5y; Fri, 02 Sep 2016 21:14:40 +0800 Date: Fri, 2 Sep 2016 21:14:39 +0800 From: Herbert Xu To: Harald van Dijk Cc: luigi.tarenga@gmail.com, dash@vger.kernel.org Subject: Re: [BUG] regression in builtin echo Message-ID: <20160902131439.GA12162@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <3efcd42c-e20b-3506-3d62-69b85c027ef4@gigawatt.nl> Organization: Core X-Newsgroups: apana.lists.os.linux.dash User-Agent: Mutt/1.5.21 (2010-09-15) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Harald van Dijk 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 Signed-off-by: Herbert Xu 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';