From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AA2B6C6FA83 for ; Sun, 11 Sep 2022 09:37:59 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 541FE841F8; Sun, 11 Sep 2022 11:37:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="RGD8K+Jk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EC72C84382; Sun, 11 Sep 2022 11:37:55 +0200 (CEST) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B731784133 for ; Sun, 11 Sep 2022 11:37:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ADDE560F3E for ; Sun, 11 Sep 2022 09:37:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E40D9C433D6 for ; Sun, 11 Sep 2022 09:37:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662889072; bh=HN3bEbNpXATqwfQUFr7CAX66NCyT84iUdWmMBTrf0Kc=; h=From:To:Subject:Date:From; b=RGD8K+JkjiVvY7oGR/snNrjCPA3QiJ8act/zJo1m91c1wp0S0b2FgI7UKS+S4xgh7 Ynux332WijjufRofwq9FRz6tl7z0n2FPm+ckIR2+/KwF8DKPTJKpcHh8O1sEHSwoe3 R0HX5OXnLkoPbWqFYI897aa1jbBA/qVbi9YOv2YeySHvi6E5CBphw38dX7AGb/VLF+ e5mTbanp7jf5w5aY4U2uwIThcK1FgyeCQ/RdFExp3tGNZgvnTpqRGKS9EoySKM0LBa oYRnAPGGcHjmkMlI8HL6tfV6qktqmoUkExI5H0wX0MNOYXVqx/wwF4/OBaoy+5+PXO IfLglsDGsuJUg== Received: by pali.im (Postfix) id E58F1878; Sun, 11 Sep 2022 11:37:48 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: u-boot@lists.denx.de Subject: [PATCH] display_options: print_size: Fix order overflow Date: Sun, 11 Sep 2022 11:37:07 +0200 Message-Id: <20220911093707.9434-1-pali@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Function print_size() round size to the nearst value with one decimal fraction number. But in special cases also unit order may overflow. For example value 1073689396 is printed as "1024 MiB" and value 1073741824 as "1 GiB". Fix this issue by detecting order overflow and increasing unit order. With this change also value 1073689396 is printed as "1 GiB". Signed-off-by: Pali Rohár --- lib/display_options.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/display_options.c b/lib/display_options.c index 360b01bcf5ff..c281c1d2c10d 100644 --- a/lib/display_options.c +++ b/lib/display_options.c @@ -126,6 +126,12 @@ void print_size(uint64_t size, const char *s) if (m >= 10) { m -= 10; n += 1; + + if (n == 1024 && i > 0) { + n = 1; + m = 0; + c = names[i - 1]; + } } } -- 2.20.1