aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/bbox.cc
diff options
context:
space:
mode:
authorschnetter <>2003-08-15 07:32:00 +0000
committerschnetter <>2003-08-15 07:32:00 +0000
commit0bc5df6a7a6d19cf3f46b0ee4ed9578835601336 (patch)
tree581412153b3eacc86e3145a7a4b722a1064ddd7b /Carpet/CarpetLib/src/bbox.cc
parentb9349e250dc73b0f74dd21be675abc199614e39a (diff)
Check for overflow in calculating bbox sizes.
darcs-hash:20030815073254-07bb3-d964703599463eb0657c0d6c6a00d3450fc3c31d.gz
Diffstat (limited to 'Carpet/CarpetLib/src/bbox.cc')
-rw-r--r--Carpet/CarpetLib/src/bbox.cc23
1 files changed, 20 insertions, 3 deletions
diff --git a/Carpet/CarpetLib/src/bbox.cc b/Carpet/CarpetLib/src/bbox.cc
index 0e11b9bfc..38f2c6808 100644
--- a/Carpet/CarpetLib/src/bbox.cc
+++ b/Carpet/CarpetLib/src/bbox.cc
@@ -1,8 +1,9 @@
-// $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/bbox.cc,v 1.15 2003/05/13 12:14:00 schnetter Exp $
+// $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/bbox.cc,v 1.16 2003/08/15 09:32:54 schnetter Exp $
#include <assert.h>
#include <iostream>
+#include <limits>
#include "defs.hh"
#include "vect.hh"
@@ -41,13 +42,29 @@ bbox<T,D>::bbox (const vect<T,D>& lower, const vect<T,D>& upper,
template<class T, int D>
T bbox<T,D>::size () const {
if (empty()) return 0;
- return prod(shape());
+// return prod(shape());
+ const vect<T,D> sh(shape());
+ int sz = 1, max = numeric_limits<T>::max();
+ for (int d=0; d<D; ++d) {
+ assert (sh[d] <= max);
+ sz *= sh[d];
+ max /= sh[d];
+ }
+ return sz;
}
template<class T, int D>
T bbox<T,D>::num_points () const {
if (empty()) return 0;
- return prod((shape()+stride()-1)/stride());
+// return prod((shape()+stride()-1)/stride());
+ const vect<T,D> sh((shape()+stride()-1)/stride());
+ int sz = 1, max = numeric_limits<T>::max();
+ for (int d=0; d<D; ++d) {
+ assert (sh[d] <= max);
+ sz *= sh[d];
+ max /= sh[d];
+ }
+ return sz;
}
// Queries