# HG changeset patch # User jwe # Date 1098211248 0 # Node ID c6ef19da4b24238f6e177c8b1129708783d08b34 # Parent cab27aa905c42c98a093c0aa05d2b39a795bc774 [project @ 2004-10-19 18:40:48 by jwe] diff -r cab27aa905c4 -r c6ef19da4b24 liboctave/Array.cc --- a/liboctave/Array.cc Tue Oct 19 15:29:15 2004 +0000 +++ b/liboctave/Array.cc Tue Oct 19 18:40:48 2004 +0000 @@ -2940,7 +2940,9 @@ if (n_idx < lhs_dims_len) { - // Collapse dimensions beyond last index. + // Collapse dimensions beyond last index. Note that we + // delay resizing LHS until we know that the assignment will + // succeed. if (liboctave_wfi_flag && ! (idx(n_idx-1).is_colon ())) (*current_liboctave_warning_handler) @@ -2951,10 +2953,6 @@ lhs_dims.resize (n_idx); - lhs.resize (lhs_dims); - - lhs_dims = lhs.dims (); - lhs_dims_len = lhs_dims.length (); } @@ -3010,6 +3008,11 @@ } else { + // Determine final dimensions for LHS and reset the + // current size of the LHS. Note that we delay actually + // resizing LHS until we know that the assignment will + // succeed. + if (n_idx < orig_lhs_dims_len) { for (int i = 0; i < n_idx-1; i++) @@ -3018,9 +3021,7 @@ else final_lhs_dims = new_dims; - lhs.resize_and_fill (new_dims, rfv); - - lhs_dims = lhs.dims (); + lhs_dims = new_dims; lhs_dims_len = lhs_dims.length (); @@ -3028,6 +3029,8 @@ if (rhs_is_scalar) { + lhs.resize_and_fill (new_dims, rfv); + if (! final_lhs_dims.any_zero ()) { int n = Array::get_size (frozen_len); @@ -3085,6 +3088,8 @@ } else { + lhs.resize_and_fill (new_dims, rfv); + if (! final_lhs_dims.any_zero ()) { int n = Array::get_size (frozen_len); @@ -3105,10 +3110,12 @@ } } - lhs.resize (final_lhs_dims); + if (retval != 0) + lhs.resize (final_lhs_dims); } - lhs.chop_trailing_singletons (); + if (retval != 0) + lhs.chop_trailing_singletons (); lhs.clear_index (); diff -r cab27aa905c4 -r c6ef19da4b24 liboctave/ChangeLog --- a/liboctave/ChangeLog Tue Oct 19 15:29:15 2004 +0000 +++ b/liboctave/ChangeLog Tue Oct 19 18:40:48 2004 +0000 @@ -1,3 +1,7 @@ +2004-10-19 John W. Eaton + + * Array.cc (assignN): Avoid resizing if assignment will fail. + 2004-10-18 John W. Eaton * Array.cc (assign2): Save result of squeeze operation.