From bug-request at octave dot org Thu Dec 8 13:55:37 2005 Subject: Octave segfaults on a valid command line From: "John W. Eaton" To: "Michael Smolsky" Cc: bug-octave at bevo dot che dot wisc dot edu Date: Thu, 8 Dec 2005 14:55:30 -0500 | Thanks for maintaining a great product. Please think of Octave as a community project that is developed and enjoyed by all its users rather than a product (which seems to imply that it is something produced by others to be consumed by users). | Octave crashes on the following command line: | | clear,u=[1,2,3];v=find(u>100);for i=u(v).',i,end I'm not able to reproduce the crash in the current recommended version (2.1.72) or a copy built from the current CVS sources. OTOH, theere seems to be a compatibility problem such that for i = zeros (0, N), i, endfor doesn't do the right thing in Octave (it should assign [](0x1) to i and go through the loop N times. For that problem, please try the following patch. These changes are relative to the current 2.1.x branch in the CVS archive. A similar change will be checked in to the main CVS branch (2.9.x) soon. Thanks, jwe src/ChangeLog 2005-12-08 John W. Eaton * pt-loop.cc (DO_ND_LOOP): Simplify. New arg, TYPE. Change all uses. (simple_for_loop_command::eval): Correctly handle N-d numeric and cell arrays when only the first dimension is 0. Index: src/pt-loop.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/pt-loop.cc,v retrieving revision 1.26.2.2 diff -u -r1.26.2.2 pt-loop.cc --- src/pt-loop.cc 26 Apr 2005 19:43:59 -0000 1.26.2.2 +++ src/pt-loop.cc 8 Dec 2005 19:50:53 -0000 at @ -242,20 +242,25 @@ } \ while (0) -#define DO_ND_LOOP(arg) \ +#define DO_ND_LOOP(TYPE, ARG) \ do \ { \ - int ndims = dv.length (); \ - Array idx; \ - int steps = dv.numel () / dv (0); \ - idx.resize (ndims, idx_vector (1)); \ - idx (0) = idx_vector (':'); \ + int steps = dv(1); \ \ for (int i = 0; i < steps; i++) \ { \ MAYBE_DO_BREAKPOINT; \ \ - octave_value val (arg.index(idx)); \ + TYPE tmp; \ + \ + int nr = ARG.rows (); \ + \ + tmp.resize (dim_vector (nr, 1)); \ + \ + for (int j = 0; j < nr; j++) \ + tmp.xelem (j) = ARG.xelem (j, i); \ + \ + octave_value val (tmp); \ \ bool quit = false; \ \ at @ -265,14 +270,6 @@ if (quit) \ break; \ \ - for (int j = 1; j < ndims; j++) \ - { \ - idx(j) = idx_vector (idx(j)(0) + 2); \ - if (idx(j)(0) < dv(j)) \ - break; \ - else \ - idx(j) = idx_vector (1); \ - } \ } \ } \ while (0) at @ -386,12 +383,27 @@ if (error_state) goto cleanup; - if (dv.numel () > 0) + // XXX FIXME XXX -- maybe we need a function for this? + int ndims = dv.length (); + for (int i = 2; i < ndims; i++) + dv(1) *= dv(i); + + if (dv(1) > 0) { if (rhs.is_real_type ()) - DO_ND_LOOP(m_tmp); + { + if (ndims > 2) + m_tmp = m_tmp.reshape (dv); + + DO_ND_LOOP(NDArray, m_tmp); + } else - DO_ND_LOOP(cm_tmp); + { + if (ndims > 2) + cm_tmp = cm_tmp.reshape (dv); + + DO_ND_LOOP(ComplexNDArray, cm_tmp); + } } } else if (rhs.is_map ()) at @ -423,8 +435,18 @@ dim_vector dv = c_tmp.dims (); - if (dv.numel () > 0) - DO_ND_LOOP(c_tmp); + // XXX FIXME XXX -- maybe we need a function for this? + int ndims = dv.length (); + for (int i = 2; i < ndims; i++) + dv(1) *= dv(i); + + if (dv(1) > 0) + { + if (ndims > 2) + c_tmp = c_tmp.reshape (dv); + + DO_ND_LOOP(Cell, c_tmp); + } } else { ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------