[Dune-devel] Out-of-bound array checks (was: Re: GSOC2013)

Markus Blatt markus at dr-blatt.de
Wed Apr 17 10:56:56 CEST 2013


Hi,

On Tue, Apr 16, 2013 at 09:16:03PM +0530, shailesh borkar wrote:
> Hello everyone,
> 	While going through the code in dune/common/array.hh file, i found
> that we have not checked the array index bound condition in
> 
> reference operator[] (size_type i)
> {
>       return a[i];
> }

For performance reasons, we do not want tests in productive codes.

> So it will be better if we check the condition for index of array,
> reference operator[] (size_type i)
> {
> 	assert(i<=(N-1))//i should be less than N
> 	return a[i];
> }

why not i<N?
The reason why this has not been done, is probably that we never needed it
yet and people tend to only implement things that they really
need. Apart from that this might be a worthwile addition. If you want
to have this and are willing to invest time, then you should provide a
complete patch for discussion to our bugtracker. But do not exspect
too much response.

> 
> Also in fmatrix.hh file, in copy constructor
> FieldVector (const FieldVector & x) : _data(x._data)
> {}
> 
> we should check for equality of sizes
> FieldVector (const FieldVector & x)
> {
> 	assert(SIZE==x.size())
> 	_data=x._data;
> }

This check is _really_ superfluous as the argument of the copy
constructor has the same type as the object. Same type for C++
template classes means same class name and template arguments. SIZE is
a template argument and therefore the check _is_ always true, isn't
it.

Cheers,

Markus

-- 
Do you need more support with DUNE or HPC in general? 

Dr. Markus Blatt - HPC-Simulation-Software & Services http://www.dr-blatt.de
Hans-Bunte-Str. 8-10, 69123 Heidelberg, Germany
Tel.: +49 (0) 160 97590858  Fax: +49 (0)322 1108991658 




More information about the Dune-devel mailing list