Whamcloud - gitweb
e2fsck: use unsigned values for memory tracking stats
authorAndreas Dilger <adilger@sun.com>
Thu, 28 May 2009 06:47:37 +0000 (00:47 -0600)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 28 May 2009 11:59:04 +0000 (07:59 -0400)
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>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/util.c

index 78c053c..89f7908 100644 (file)
@@ -330,15 +330,16 @@ void print_resource_track(const char *desc, struct resource_track *track,
                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: %uk/%uk (%uk/%uk), "),
+       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: %u, "),
-              (int) (((char *) sbrk(0)) - ((char *) track->brk_start)));
+       printf(_("Memory used: %lu, "),
+              (unsigned long) (((char *) sbrk(0)) - 
+                               ((char *) track->brk_start)));
 #endif
 #ifdef HAVE_GETRUSAGE
        getrusage(RUSAGE_SELF, &r);