All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] use unsigned values for memory tracking stats
@ 2009-05-28  6:47 Andreas Dilger
  2009-05-28 11:57 ` Theodore Tso
  0 siblings, 1 reply; 2+ messages in thread
From: Andreas Dilger @ 2009-05-28  6:47 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: linux-ext4

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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-05-28 11:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-28  6:47 [PATCH] use unsigned values for memory tracking stats Andreas Dilger
2009-05-28 11:57 ` Theodore Tso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.