cast to unsigned long long before computing to avoid overflow

This commit is contained in:
itojun 2004-03-02 03:59:17 +00:00
parent 96b84a38a0
commit 1e9b827214
1 changed files with 7 additions and 9 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: df.c,v 1.52 2004/03/02 03:50:45 itojun Exp $ */
/* $NetBSD: df.c,v 1.53 2004/03/02 03:59:17 itojun Exp $ */
/*
* Copyright (c) 1980, 1990, 1993, 1994
@ -45,7 +45,7 @@ __COPYRIGHT(
#if 0
static char sccsid[] = "@(#)df.c 8.7 (Berkeley) 4/2/94";
#else
__RCSID("$NetBSD: df.c,v 1.52 2004/03/02 03:50:45 itojun Exp $");
__RCSID("$NetBSD: df.c,v 1.53 2004/03/02 03:59:17 itojun Exp $");
#endif
#endif /* not lint */
@ -317,7 +317,8 @@ prthuman(struct statfs *sfsp, long used)
*/
#define fsbtoblk(num, fsbs, bs) \
(((fsbs) != 0 && (fsbs) < (bs)) ? \
(num) / ((bs) / (fsbs)) : (num) * ((fsbs) / (bs)))
(unsigned long long)(num) / ((bs) / (fsbs)) : \
(unsigned long long)(num) * ((fsbs) / (bs)))
/*
* Print out status about a filesystem.
@ -366,12 +367,9 @@ prtstat(struct statfs *sfsp, int maxwidth)
prthuman(sfsp, used);
else
(void)printf(" %*llu %8llu %9llu", headerlen,
(unsigned long long)fsbtoblk(sfsp->f_blocks, sfsp->f_bsize,
blocksize),
(unsigned long long)fsbtoblk(used, sfsp->f_bsize,
blocksize),
(unsigned long long)fsbtoblk(sfsp->f_bavail, sfsp->f_bsize,
blocksize));
fsbtoblk(sfsp->f_blocks, sfsp->f_bsize, blocksize),
fsbtoblk(used, sfsp->f_bsize, blocksize),
fsbtoblk(sfsp->f_bavail, sfsp->f_bsize, blocksize));
(void)printf("%7s",
availblks == 0 ? full : strpct((u_long)used, (u_long)availblks, 0));
if (iflag) {