From patchwork Thu Sep 6 07:08:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 966829 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 425WwJ12bqz9sDb for ; Thu, 6 Sep 2018 17:12:00 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id A09BDC21CB6; Thu, 6 Sep 2018 07:09:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id E8A0BC21DEC; Thu, 6 Sep 2018 07:09:00 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 76750C21CB6; Thu, 6 Sep 2018 07:08:58 +0000 (UTC) Received: from mail.bootlin.com (mail.bootlin.com [62.4.15.54]) by lists.denx.de (Postfix) with ESMTP id A02C6C21C29 for ; Thu, 6 Sep 2018 07:08:57 +0000 (UTC) Received: by mail.bootlin.com (Postfix, from userid 110) id 01EB920812; Thu, 6 Sep 2018 09:08:58 +0200 (CEST) Received: from localhost.localdomain (AAubervilliers-681-1-30-219.w90-88.abo.wanadoo.fr [90.88.15.219]) by mail.bootlin.com (Postfix) with ESMTPSA id 9CC88206FF; Thu, 6 Sep 2018 09:08:57 +0200 (CEST) From: Miquel Raynal To: Tom Rini , Jagan Teki Date: Thu, 6 Sep 2018 09:08:44 +0200 Message-Id: <20180906070854.9717-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180906070854.9717-1-miquel.raynal@bootlin.com> References: <20180906070854.9717-1-miquel.raynal@bootlin.com> Cc: Alexandre Belloni , Boris Brezillon , Antoine Tenart , Allan Nielsen , u-boot@lists.denx.de, Miquel Raynal , Stefan Roese Subject: [U-Boot] [PATCH v7 02/12] lib: strto: fix metric suffix parsing in strtoul[l] X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" While 1kB or 1kiB will be parsed correctly, 1k will return the right amount, but the metric suffix will not be escaped once the char pointer updated. Fix this situation by simplifying the move of the endp pointer. Signed-off-by: Miquel Raynal Reviewed-by: Stefan Roese --- lib/strto.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/strto.c b/lib/strto.c index b7fc31d6e5..55ff9f7437 100644 --- a/lib/strto.c +++ b/lib/strto.c @@ -94,12 +94,11 @@ unsigned long ustrtoul(const char *cp, char **endp, unsigned int base) /* fall through */ case 'k': result *= 1024; - if ((*endp)[1] == 'i') { - if ((*endp)[2] == 'B') - (*endp) += 3; - else - (*endp) += 2; - } + (*endp)++; + if (**endp == 'i') + (*endp)++; + if (**endp == 'B') + (*endp)++; } return result; } @@ -116,12 +115,11 @@ unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base) /* fall through */ case 'k': result *= 1024; - if ((*endp)[1] == 'i') { - if ((*endp)[2] == 'B') - (*endp) += 3; - else - (*endp) += 2; - } + (*endp)++; + if (**endp == 'i') + (*endp)++; + if (**endp == 'B') + (*endp)++; } return result; }