From patchwork Fri Sep 16 20:49:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 115036 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id D7490B6F9D for ; Sat, 17 Sep 2011 06:49:51 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755758Ab1IPUts (ORCPT ); Fri, 16 Sep 2011 16:49:48 -0400 Received: from sandeen.net ([63.231.237.45]:46732 "EHLO mail.sandeen.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755313Ab1IPUtq (ORCPT ); Fri, 16 Sep 2011 16:49:46 -0400 Received: by mail.sandeen.net (Postfix, from userid 500) id 75F4E4A8BA7D; Fri, 16 Sep 2011 15:49:44 -0500 (CDT) From: Eric Sandeen To: linux-ext4@vger.kernel.org Cc: Eric Sandeen Subject: [PATCH 15/25] filefrag: Fix uninitialized "expected" value Date: Fri, 16 Sep 2011 15:49:30 -0500 Message-Id: <1316206180-6375-16-git-send-email-sandeen@redhat.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1316206180-6375-1-git-send-email-sandeen@redhat.com> References: <1316206180-6375-1-git-send-email-sandeen@redhat.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org The "count" variable is only ever set if FIBMAP is used, due to the -B switch, or a fiemap failure. However, we use it unconditionally to calculate "expected" for extN files, so we can end up printing garbage. Initialize count to 0, and unless we go through the FIBMAP path, expected will be 0 as well, and in that case do not print the message. Signed-off-by: Eric Sandeen --- misc/filefrag.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/misc/filefrag.c b/misc/filefrag.c index 2795e15..b055c2b 100644 --- a/misc/filefrag.c +++ b/misc/filefrag.c @@ -272,7 +272,7 @@ static void frag_report(const char *filename) #endif int bs; long fd; - unsigned long block, last_block = 0, numblocks, i, count; + unsigned long block, last_block = 0, numblocks, i, count = 0; long bpib; /* Blocks per indirect block */ long cylgroups; int num_extents = 0, expected; @@ -373,8 +373,9 @@ static void frag_report(const char *filename) printf("%s: 1 extent found", filename); else printf("%s: %d extents found", filename, num_extents); + /* count, and thus expected, only set for indirect FIBMAP'd files */ expected = (count/((bs*8)-(fsinfo.f_files/8/cylgroups)-3))+1; - if (is_ext2 && expected < num_extents) + if (is_ext2 && expected && expected < num_extents) printf(", perfection would be %d extent%s\n", expected, (expected>1) ? "s" : ""); else