changeset 33009:38112a5ee9c6

Don't skip loop iterations if number of rows of loop array is zero (bug #55622). * pt-eval.cc (tree_evaluator::visit_simple_for_command): Don't skip loop iterations if number of rows of loop matrix is zero. Always loop over number of columns in the re-dimensioned array. If the number of steps is zero, set the loop variable to the value of the re-dimensioned array. * test/for.tst: Update tests. New tests.
author John W. Eaton <jwe@octave.org>
date Mon, 11 Feb 2019 16:01:03 +0000
parents 8adbe07a6835
children 4c53ef3f3671
files libinterp/parse-tree/pt-eval.cc test/for.tst
diffstat 2 files changed, 22 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-eval.cc	Mon Feb 12 17:14:44 2024 +0100
+++ b/libinterp/parse-tree/pt-eval.cc	Mon Feb 11 16:01:03 2019 +0000
@@ -3221,7 +3221,7 @@
       if (rhs.ndims () > 2)
         arg = arg.reshape (dv);
 
-      if (nrows > 0 && steps > 0)
+      if (steps > 0)
         {
           octave_value_list idx;
           octave_idx_type iidx;
--- a/test/for.tst	Mon Feb 12 17:14:44 2024 +0100
+++ b/test/for.tst	Mon Feb 11 16:01:03 2019 +0000
@@ -130,15 +130,15 @@
 %! __printf_assert__ ("\n");
 %! assert (__prog_output_assert__ ("1234"));
 
-%!test <*50893>
+%!test <*55622>
 %! cnt = 0;
 %! for k = zeros (0,3)
 %!   cnt++;
 %! endfor
-%! assert (cnt, 0);
-%! assert (k, zeros (0,3));
+%! assert (cnt, 3);
+%! assert (k, zeros (0,1));
 
-%!test <*50893>
+%!test <*55622>
 %! cnt = 0;
 %! for k = zeros (3,0)
 %!   cnt++;
@@ -159,8 +159,24 @@
 %! for k = cell (0,3)
 %!   cnt++;
 %! endfor
+%! assert (cnt, 3);
+%! assert (k, cell (0,1));
+
+%!test <*55622>
+%! cnt = 0;
+%! for k = zeros (1,2,3);
+%!   cnt++;
+%! endfor
+%! assert (cnt, 6);
+%! assert (k, 0);
+
+%!test <*55622>
+%! cnt = 0;
+%! for k = zeros (1,2,0);
+%!   cnt++;
+%! endfor
 %! assert (cnt, 0);
-%! assert (k, cell (0,3));
+%! assert (k, zeros (1,0));
 
 %!test <*45143>
 %! warning ("on", "Octave:infinite-loop", "local");