From patchwork Sat Dec 8 09:34:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Heimpold X-Patchwork-Id: 10719301 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF07F15A6 for ; Sat, 8 Dec 2018 09:34:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC6B729EC8 for ; Sat, 8 Dec 2018 09:34:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A6902AD8C; Sat, 8 Dec 2018 09:34:59 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,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 40AB129EC8 for ; Sat, 8 Dec 2018 09:34:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726103AbeLHJe5 (ORCPT ); Sat, 8 Dec 2018 04:34:57 -0500 Received: from mo4-p01-ob.smtp.rzone.de ([85.215.255.51]:16722 "EHLO mo4-p01-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726099AbeLHJe5 (ORCPT ); Sat, 8 Dec 2018 04:34:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1544261695; s=strato-dkim-0002; d=heimpold.de; h=References:Message-Id:Date:Subject:Cc:To:From:X-RZG-CLASS-ID: X-RZG-AUTH:From:Subject:Sender; bh=8irZkXDfDM06ov6Rw2HmyHVroVP6LVVhjRfTF+rUdXo=; b=XWpeW7YwjuSOwd068SZyOuX3aEGb0Qffbg5Q585mvJb2XPoQvTSPQWP47fjT4f5Y5V ptOX3N7GopOBZMyshQon3QxYlDV5/lWBqxcfEIxeSUwXBMVJ+g1xqqy/K5CiP5ULEItR sya1ZDl1wEcYDiuZC7UpX3TER8rfGUgI1E0cbkdTWHjAGzqEhEbeSAk3FInbpvUa7OyV B0eoIsvyyP94hafZmJyD/veEL4uCWIPTcZzKv5l13l5WQPpoMSEVMHHwbLRDk75ZuZzq kgdUGlGNgEY9afdatLN/NJsu/TD3rGHFyzc+E3D9F7VqEIncNrnlhUWq6IrJWvHaGI6l ddCg== X-RZG-AUTH: ":O2kGeEG7b/pS1EW8QnKjhhg/vO4pzqdNytq77N6ZPUGwIpLOmsCM+BB/JuKi9Rok/o3y/V93OIyw" X-RZG-CLASS-ID: mo00 Received: from tonne.mhei.heimpold.itr by smtp.strato.de (RZmta 44.6 DYNA|AUTH) with ESMTPSA id w096b8uB89YsAAj (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Sat, 8 Dec 2018 10:34:54 +0100 (CET) Received: from kerker.mhei.heimpold.itr (kerker.mhei.heimpold.itr [192.168.8.1]) by tonne.mhei.heimpold.itr (Postfix) with ESMTP id 4D6921C5E17; Sat, 8 Dec 2018 10:34:53 +0100 (CET) From: Michael Heimpold To: chris@printf.net Cc: Michael Heimpold , Wolfram Sang , Wolfram Sang , "linux-mmc@vger.kernel.org" Subject: [PATCH mmc-utils] One further optimization of trimming routine Date: Sat, 8 Dec 2018 10:34:41 +0100 Message-Id: <20181208093441.10886-1-mhei@heimpold.de> X-Mailer: git-send-email 2.17.1 References: <20181208055630.GB12686@void.printf.net> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The last change to the trimming routine made it more efficient, however, we can even get rid of the memmove() as we leave the function with strdup() anyway. Signed-off-by: Michael Heimpold I got a compile error with GCC7. When trimming white spaces from strings lsmmc uses strncpy with overlapping memory areas. This is not allowed. In addition, the implementation was not efficient with calling strlen and strncpy once per iteration. Refactor the code to be valid and more effective. --- lsmmc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lsmmc.c b/lsmmc.c index 9737b37..86be802 100644 --- a/lsmmc.c +++ b/lsmmc.c @@ -358,10 +358,9 @@ char *read_file(char *name) start++; len--; } - memmove(line, start, len); - line[len] = '\0'; + start[len] = '\0'; - return strdup(line); + return strdup(start); } /* Hexadecimal string parsing functions */