From patchwork Mon Jul 9 17:02:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Carrier X-Patchwork-Id: 1174101 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 41A5E40B21 for ; Mon, 9 Jul 2012 17:02:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752354Ab2GIRCu (ORCPT ); Mon, 9 Jul 2012 13:02:50 -0400 Received: from mail-lb0-f174.google.com ([209.85.217.174]:62743 "EHLO mail-lb0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751191Ab2GIRCt (ORCPT ); Mon, 9 Jul 2012 13:02:49 -0400 Received: by mail-lb0-f174.google.com with SMTP id gm6so20424208lbb.19 for ; Mon, 09 Jul 2012 10:02:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=NRzxRhLmkvQKYqEr0xSpbK5RIemvncDPZthT4rsrXmg=; b=fW709LXM4HqejNxdU80W4QTgVceoo7dGlHlEKRkVFgv6CKHDVJ5QGk4Sxy4WZXQm3q 5IFBEYCTephU7nFnJKb99utIeTKPnfZOrW1as9BNCHsWJXkTUfwOJ7yBOiZX3SEVlpbh O6AIQYctrAdRN32srBd3ASQgYnqDjYmi5BiaRmS48ybJhKgAGb2HZiFIgJVotgPxI9EM WATZmd8btMUYXbVHVgc0EvidoE8Y1FYbjyOIFBqym2Usx2f2gx8gYu5+tDwSbRsgcutN kafgVfZVCGYshmqG6dcVL8dYsfyO9Fu2DyC2E+HbZMT6Fm8YjwIo8lhngNUAgBDZ0AGq pjJQ== Received: by 10.152.113.199 with SMTP id ja7mr41184059lab.10.1341853368795; Mon, 09 Jul 2012 10:02:48 -0700 (PDT) Received: from bar.spotify.net (155.60.236.194.office.spotify.net. [194.236.60.155]) by mx.google.com with ESMTPS id sy1sm47813914lab.13.2012.07.09.10.02.47 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 09 Jul 2012 10:02:48 -0700 (PDT) From: Pierre Carrier To: linux-btrfs@vger.kernel.org Cc: Pierre Carrier Subject: [PATCH 1/2] utils.c: fix sizes in B & malloc in pretty_sizes Date: Mon, 9 Jul 2012 17:02:26 +0000 Message-Id: <1341853347-11788-2-git-send-email-pierre@spotify.com> X-Mailer: git-send-email 1.7.11.1 In-Reply-To: <1341853347-11788-1-git-send-email-pierre@spotify.com> References: <1341853347-11788-1-git-send-email-pierre@spotify.com> X-Gm-Message-State: ALoCoQmMuIwBAkuG1Neuvjg7lW1Gt8F8J+P6snR4cc0BJBW3L8ZB92W8CLD9EP/X5vfRVSQ2hSd4 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Before, sizes below 1KB where displayed in KB, but without a unit. Signed-off-by: Pierre Carrier diff --git a/utils.c b/utils.c index aade9e2..dde0513 100644 --- a/utils.c +++ b/utils.c @@ -1108,13 +1108,20 @@ char *pretty_sizes(u64 size) size /= 1024; num_divs++; } - if (num_divs == 0) + if (num_divs == 0) { num_divs = 1; + fraction = (float)fract_size; + } else + fraction = (float)fract_size / 1024; + if (num_divs > ARRAY_SIZE(size_strs)) return NULL; - fraction = (float)fract_size / 1024; + pretty = malloc(pretty_len); + if (!pretty) + return NULL; + snprintf(pretty, pretty_len, "%.2f%s", fraction, size_strs[num_divs-1]); return pretty; }