[PATCH] use unsigned values for memory tracking stats

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxx>

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.

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux