# HG changeset patch # User John W. Eaton # Date 1336753993 14400 # Node ID edf9ca8a92a8c9a7957333cc211cc91d4c2eee6d # Parent 6980b0f35df97c065a5917c484862bff0701bb88 when redimensioning, always pad dim_vector objects with 1 (bug #33216) * dim-vector.cc (dim_vector::redim): Always pad with 1. * dim-vector.h (dim_vector::redim): Update comment. * Array.cc (Array::assign): Query dimensions for all zeros before redimensioning. * ov-struct.cc: New test. diff -r 6980b0f35df9 -r edf9ca8a92a8 liboctave/Array.cc --- a/liboctave/Array.cc Thu May 03 17:32:33 2012 -0400 +++ b/liboctave/Array.cc Fri May 11 12:33:13 2012 -0400 @@ -1164,16 +1164,21 @@ Array::assign (const idx_vector& i, const idx_vector& j, const Array& rhs, const T& rfv) { + bool initial_dims_all_zero = dimensions.all_zero (); + // Get RHS extents, discarding singletons. dim_vector rhdv = rhs.dims (); + // Get LHS extents, allowing Fortran indexing in the second dim. dim_vector dv = dimensions.redim (2); + // Check for out-of-bounds and form resizing dimensions. dim_vector rdv; + // In the special when all dimensions are zero, colons are allowed // to inquire the shape of RHS. The rules are more obscure, so we // solve that elsewhere. - if (dv.all_zero ()) + if (initial_dims_all_zero) rdv = zero_dims_inquire (i, j, rhdv); else { @@ -1267,6 +1272,8 @@ assign (ia(0), ia(1), rhs, rfv); else if (ial > 0) { + bool initial_dims_all_zero = dimensions.all_zero (); + // Get RHS extents, discarding singletons. dim_vector rhdv = rhs.dims (); @@ -1279,7 +1286,7 @@ // In the special when all dimensions are zero, colons are // allowed to inquire the shape of RHS. The rules are more // obscure, so we solve that elsewhere. - if (dv.all_zero ()) + if (initial_dims_all_zero) rdv = zero_dims_inquire (ia, rhdv); else { diff -r 6980b0f35df9 -r edf9ca8a92a8 liboctave/dim-vector.cc --- a/liboctave/dim-vector.cc Thu May 03 17:32:33 2012 -0400 +++ b/liboctave/dim-vector.cc Fri May 11 12:33:13 2012 -0400 @@ -272,16 +272,11 @@ { dim_vector retval = alloc (n); - int pad = 0; for (int i = 0; i < n_dims; i++) - { - retval.rep[i] = rep[i]; - if (rep[i] != 0) - pad = 1; - } + retval.rep[i] = rep[i]; for (int i = n_dims; i < n; i++) - retval.rep[i] = pad; + retval.rep[i] = 1; return retval; } diff -r 6980b0f35df9 -r edf9ca8a92a8 liboctave/dim-vector.h --- a/liboctave/dim-vector.h Thu May 03 17:32:33 2012 -0400 +++ b/liboctave/dim-vector.h Fri May 11 12:33:13 2012 -0400 @@ -381,8 +381,7 @@ // Force certain dimensionality, preserving numel (). Missing // dimensions are set to 1, redundant are folded into the trailing // one. If n = 1, the result is 2d and the second dim is 1 - // (dim_vectors are always at least 2D). If the original dimensions - // were all zero, the padding value is zero. + // (dim_vectors are always at least 2D). dim_vector redim (int n) const; diff -r 6980b0f35df9 -r edf9ca8a92a8 src/ov-struct.cc --- a/src/ov-struct.cc Thu May 03 17:32:33 2012 -0400 +++ b/src/ov-struct.cc Fri May 11 12:33:13 2012 -0400 @@ -2149,6 +2149,8 @@ %! assert (fieldnames (s), keys'); %!assert (cell2struct ({1; 2}, {"a"; "b"}), struct ("a", 1, "b", 2)); + +%!assert (cell2struct ({}, {"f"}, 3), struct ("f", {})); */