Mercurial > octave-dspies
comparison liboctave/array/Array.cc @ 19009:8d47ce2053f2 draft
Added safety checks to Array::xelem
There's no reason to have a method which never checks invariants, ever. Added
debugging checks to Array::xelem to help catch and debug out-of-bounds errors
and reference overlap
* configure.ac: Added configuration option for uniqueness-checking with xelem
* jit-typeinfo.cc (octave_jit_paren_scalar): Call const Array::xelem rather
than Array::xelem
* Array-util.h, Array-util.cc (check_out_of_range): Extract common pattern to
method
(check_index): Methods to check index is in-bounds
(compute_index): Added bool parameter check. does not check bounds when check
is false and BOUNDS_CHECKING is off
* Array.h, Array.cc (xelem): Use methods from Array-util.h to compute indices
(is_unique): Check if this is the only reference to data
* CmplxQR.cc, dbleQR.cc, fCmplxQR.cc, floatQR.cc
(form): Move second assignment to after the call to xelem
* lo-array-gripes.h, lo-array-gripes.cc (gripe_modifying_nonunique): Added
error message for when non-const xelem is called on non-unique array
author | David Spies <dnspies@gmail.com> |
---|---|
date | Mon, 14 Jul 2014 13:07:59 -0600 |
parents | 2e0613dadfee |
children |
comparison
equal
deleted
inserted
replaced
19008:80ca3b05d77c | 19009:8d47ce2053f2 |
---|---|
34 #include <vector> | 34 #include <vector> |
35 #include <algorithm> | 35 #include <algorithm> |
36 #include <new> | 36 #include <new> |
37 | 37 |
38 #include "Array.h" | 38 #include "Array.h" |
39 #include "Array-util.h" | |
40 #include "idx-vector.h" | 39 #include "idx-vector.h" |
41 #include "lo-error.h" | 40 #include "lo-error.h" |
42 #include "oct-locbuf.h" | 41 #include "oct-locbuf.h" |
43 | 42 |
44 // One dimensional array class. Handles the reference counting for | 43 // One dimensional array class. Handles the reference counting for |
187 template <class T> | 186 template <class T> |
188 T& | 187 T& |
189 Array<T>::checkelem (octave_idx_type n) | 188 Array<T>::checkelem (octave_idx_type n) |
190 { | 189 { |
191 // Do checks directly to avoid recomputing slice_len. | 190 // Do checks directly to avoid recomputing slice_len. |
192 if (n < 0) | 191 check_index_bounds (1, 0, n, slice_len); |
193 gripe_invalid_index (); | |
194 if (n >= slice_len) | |
195 gripe_index_out_of_range (1, 1, n+1, slice_len); | |
196 | 192 |
197 return elem (n); | 193 return elem (n); |
198 } | 194 } |
199 | 195 |
200 template <class T> | 196 template <class T> |