Mercurial > hg > octave-lyh
changeset 11850:f25094e43897 release-3-0-x
clear index before throwing error in Array indexed assignment functions
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 21 Sep 2008 08:21:52 +0200 |
parents | 74802398931b |
children | 651401a1c39b |
files | liboctave/Array.cc liboctave/ChangeLog |
diffstat | 2 files changed, 54 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -2008,8 +2008,12 @@ retval = index (idx[0]); } else - (*current_liboctave_error_handler) - ("Array<T>::value: invalid number of indices specified"); + { + clear_index (); + + (*current_liboctave_error_handler) + ("Array<T>::value: invalid number of indices specified"); + } clear_index (); @@ -2532,6 +2536,8 @@ } else { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A(I) = X: X must be a scalar or a vector with same length as I"); @@ -2540,6 +2546,8 @@ } else { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A(I) = X: unable to resize A"); @@ -2560,11 +2568,17 @@ lhs.xelem (i) = rhs.elem (i); } else if (rhs_len != lhs_len) - (*current_liboctave_error_handler) - ("A(:) = X: A must be the same size as X"); + { + lhs.clear_index (); + + (*current_liboctave_error_handler) + ("A(:) = X: A must be the same size as X"); + } } else if (! (rhs_len == 1 || rhs_len == 0)) { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A([]) = X: X must also be an empty matrix or a scalar"); @@ -2626,6 +2640,7 @@ break; default: + lhs.clear_index (); (*current_liboctave_error_handler) ("Array<T>::assign2: Dimension mismatch"); return 0; @@ -2740,6 +2755,8 @@ { if (! (rhs_is_scalar || (rhs_nr == 0 || rhs_nc == 0))) { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A([], []) = X: X must be an empty matrix or a scalar"); @@ -2748,12 +2765,10 @@ } else { - (*current_liboctave_error_handler) - ("A(I, J) = X: X must be a scalar or the number of elements in I must"); + lhs.clear_index (); + (*current_liboctave_error_handler) - ("match the number of rows in X and the number of elements in J must"); - (*current_liboctave_error_handler) - ("match the number of columns in X"); + ("A(I, J) = X: X must be a scalar or the number of elements in I must match the number of rows in X and the number of elements in J must match the number of columns in X"); retval = 0; } @@ -2871,8 +2886,14 @@ else if (len == 0) { if (! (rhs_is_scalar || (rhs_nr == 0 || rhs_nc == 0))) - (*current_liboctave_error_handler) - ("A([]) = X: X must be an empty matrix or scalar"); + { + lhs.clear_index (); + + (*current_liboctave_error_handler) + ("A([]) = X: X must be an empty matrix or scalar"); + + retval = 0; + } } else if (len == rhs_nr * rhs_nc) { @@ -2914,6 +2935,8 @@ } else { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A(I) = X: X must be a scalar or a matrix with the same size as I"); @@ -2960,6 +2983,8 @@ } else if (n_idx == 0) { + lhs.clear_index (); + (*current_liboctave_error_handler) ("invalid number of indices for matrix expression"); @@ -2986,6 +3011,8 @@ { if (! (rhs_dims.all_ones () || rhs_dims.any_zero ())) { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A([]) = X: X must be an empty matrix or scalar"); @@ -3034,6 +3061,8 @@ } else { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A(I) = X: X must be a scalar or a matrix with the same size as I"); @@ -3145,6 +3174,8 @@ } else if (new_dims_numel != rhs_dims_numel || new_dims_vec > 1) { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A(IDX-LIST) = RHS: mismatched index and RHS dimension"); return retval; @@ -3172,6 +3203,8 @@ k++; else if (nelem != 1) { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A(IDX-LIST) = RHS: mismatched index and RHS dimension"); return retval; @@ -3214,6 +3247,8 @@ // be an error, because we don't know how to undo that // later... + lhs.clear_index (); + (*current_liboctave_error_handler) ("array index %d (= %d) for assignment requires invalid resizing operation", n_idx, new_dims(n_idx-1)); @@ -3340,6 +3375,8 @@ if (n != rhs.numel ()) { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A(IDX-LIST) = X: X must be a scalar or size of X must equal number of elements indexed by IDX-LIST");
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,9 @@ +2008-09-19 John W. Eaton <jwe@octave.org> + + * Array.cc (assign1, assign2, assignN): + Clear lhs index before throwing error. + (Array<T>::value): Clear index before throwing error. + 2008-09-18 Jaroslav Hajek <highegg@gmail.com> * Array.cc (maybe_delete_elements_2 (idx_vector&)): Fix tests to get