Skip to contentSkip to conversation

use unsigned values for memory tracking stats

PATCH Applied Andreas Dilger 2 participants 2 messages May 28, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 use unsigned values for memory tracking stats

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.

e2fsck/util.c +4 -4
Index: 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.

Applied
#1 lore raw
Quoted 5 lines · Andreas Dilger

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.

Applied, thanks

- Ted