Source-Changes-HG archive

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

[src/trunk]: src/sbin/dump range-check what we assign to int cachebufs from c...



details:   https://anonhg.NetBSD.org/src/rev/6c9a285997ce
branches:  trunk
changeset: 751184:6c9a285997ce
user:      spz <spz%NetBSD.org@localhost>
date:      Wed Jan 27 12:20:25 2010 +0000

description:
range-check what we assign to int cachebufs from calculations with
uint64_t usermem. This only becomes relevant if you have several TB of RAM.
Promoting cachebufs to uint64_t is not necessary as it gets limited to
(currently) 512 anyway.

fixes the last issue of PR: 19852

diffstat:

 sbin/dump/rcache.c |  10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diffs (38 lines):

diff -r 36637edba299 -r 6c9a285997ce sbin/dump/rcache.c
--- a/sbin/dump/rcache.c        Wed Jan 27 11:02:03 2010 +0000
+++ b/sbin/dump/rcache.c        Wed Jan 27 12:20:25 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rcache.c,v 1.22 2008/04/28 20:23:08 martin Exp $       */
+/*     $NetBSD: rcache.c,v 1.23 2010/01/27 12:20:25 spz Exp $  */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: rcache.c,v 1.22 2008/04/28 20:23:08 martin Exp $");
+__RCSID("$NetBSD: rcache.c,v 1.23 2010/01/27 12:20:25 spz Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -106,7 +106,7 @@
        nblksread <<= ufsib->ufs_bshift - dev_bshift;
 
        if (cachesize == -1) {  /* Compute from memory available */
-               uint64_t usermem;
+               uint64_t usermem, cachetmp;
                int mib[2] = { CTL_HW, HW_USERMEM64 };
 
                len = sizeof(usermem);
@@ -115,7 +115,9 @@
                            strerror(errno));
                        return;
                }
-               cachebufs = (usermem / MAXMEMPART) / CSIZE;
+               cachetmp = (usermem / MAXMEMPART) / CSIZE;
+               /* for those with TB of RAM */
+               cachebufs = (cachetmp > INT_MAX) ? INT_MAX : cachetmp;
        } else {                /* User specified */
                cachebufs = cachesize;
        }



Home | Main Index | Thread Index | Old Index