From: Andreas Dilger <adilger@sun.com>
To: "Theodore Ts'o" <tytso@mit.edu>
Cc: linux-ext4@vger.kernel.org
Subject: [PATCH] use unsigned values for memory tracking stats
Date: Thu, 28 May 2009 00:47:37 -0600 [thread overview]
Message-ID: <20090528064737.GF3218@webber.adilger.int> (raw)
Use unsigned values for printing memory tracking to avoid overflows.
The mallinfo() data is currently signed ints, but it might change in
the future so we may as well compute/print unsigned longs.
Signed-off-by: Andreas Dilger <adilger@sun.com>
Index: e2fsprogs-cfs/e2fsck/util.c
===================================================================
--- e2fsprogs-cfs.orig/e2fsck/util.c
+++ e2fsprogs-cfs/e2fsck/util.c
@@ -330,15 +330,15 @@ void print_resource_track(const char *de
printf("%s: ", desc);
#ifdef HAVE_MALLINFO
-#define kbytes(x) (((x) + 1023) / 1024)
+#define kbytes(x) (((unsigned long)(x) + 1023) / 1024)
malloc_info = mallinfo();
- printf(_("Memory used: %dk/%dk (%dk/%dk), "),
+ printf(_("Memory used: %luk+%luk (%luk+%luk), "),
kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
kbytes(malloc_info.uordblks), kbytes(malloc_info.fordblks));
#else
- printf(_("Memory used: %d, "),
- (int) (((char *) sbrk(0)) - ((char *) track->brk_start)));
+ printf(_("Memory used: %lu, "),
+ (long) (((char *) sbrk(0)) - ((char *) track->brk_start)));
#endif
#ifdef HAVE_GETRUSAGE
getrusage(RUSAGE_SELF, &r);
Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.
next reply other threads:[~2009-05-28 6:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-28 6:47 Andreas Dilger [this message]
2009-05-28 11:57 ` [PATCH] use unsigned values for memory tracking stats Theodore Tso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090528064737.GF3218@webber.adilger.int \
--to=adilger@sun.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).