Module Name:    src
Committed By:   spz
Date:           Wed Jan 27 12:20:25 UTC 2010

Modified Files:
        src/sbin/dump: rcache.c

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sbin/dump/rcache.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/dump/rcache.c
diff -u src/sbin/dump/rcache.c:1.22 src/sbin/dump/rcache.c:1.23
--- src/sbin/dump/rcache.c:1.22	Mon Apr 28 20:23:08 2008
+++ src/sbin/dump/rcache.c	Wed Jan 27 12:20:25 2010
@@ -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;
 	}

Reply via email to