From b8df41cb4b6024d04748085355276a272baefc67 Mon Sep 17 00:00:00 2001 From: "Michael F. Herbst" Date: Mon, 23 Feb 2015 14:59:05 +0100 Subject: [PATCH] Use AlignedVector::size_type in TableBase::position Use AlignedVector::size_type as the integer type to carry out the calculation of the position of the element indicated by the TableIndices object. This has the advantage that a potential integer overflow for Tables with sizes less than max long int in each dimension, but with more than max long int entries is prevented. --- include/deal.II/base/table.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/include/deal.II/base/table.h b/include/deal.II/base/table.h index 7498089893..9dc7a9c5ec 100644 --- a/include/deal.II/base/table.h +++ b/include/deal.II/base/table.h @@ -593,7 +593,7 @@ protected: * Return the position of the indicated element within the array of elements * stored one after the other. This function does no index checking. */ - unsigned int position (const TableIndices &indices) const; + typename AlignedVector::size_type position (const TableIndices &indices) const; /** * Return a read-write reference to the indicated element. @@ -1987,9 +1987,11 @@ TableBase::memory_consumption () const template inline -unsigned int +typename AlignedVector::size_type TableBase::position (const TableIndices &indices) const { + typedef typename AlignedVector::size_type size_type; + // specialize this for the // different numbers of dimensions, // to make the job somewhat easier @@ -2000,13 +2002,13 @@ TableBase::position (const TableIndices &indices) const case 1: return indices[0]; case 2: - return indices[0]*table_size[1] + indices[1]; + return size_type(indices[0])*table_size[1] + indices[1]; case 3: - return ((indices[0]*table_size[1] + indices[1])*table_size[2] + return ((size_type(indices[0])*table_size[1] + indices[1])*table_size[2] + indices[2]); default: { - unsigned int s = indices[0]; + size_type s = indices[0]; for (unsigned int n=1; n