changeset 20619:96163bdd2ea1

Fix assigning into structs with trailing singleton dimensions (bug #35841) * ov-struct.cc (subsasgn): If indexing results in empty matrix, substitute a 1x1 empty cell. Change test so that if numel of indexing operation is '<= 1' operation proceeds rather than '== 1'. * struct.tst: Add BIST test for bug #35841.
author Lachlan Andrew <lachlanbis@gmail.com>
date Tue, 13 Oct 2015 09:55:46 -0700
parents 9cef0a1207e4
children b5d2ca6a690c
files libinterp/octave-value/ov-struct.cc test/struct.tst
diffstat 2 files changed, 21 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-struct.cc	Tue Oct 13 11:40:05 2015 +0100
+++ b/libinterp/octave-value/ov-struct.cc	Tue Oct 13 09:55:46 2015 -0700
@@ -334,6 +334,10 @@
                   {
                     map.contents (pkey).make_unique ();
                     tmpc = map.contents (pkey).index (idx.front (), true);
+                    // See bug #35841, assigning to struct with trailing
+                    // singleton dimensions.
+                    if (tmpc.is_empty ())
+                      tmpc = Cell (1,1);
                   }
 
                 // FIXME: better code reuse?
@@ -478,7 +482,7 @@
                         // cast to const reference, avoid forced key insertion.
                         if (idxf.all_scalars ()
                             || cmap.contents (key).index (idxf, true).numel ()
-                               == 1)
+                               <= 1)
                           {
                             map.assign (idxf,
                                         key, Cell (t_rhs.storable_value ()));
--- a/test/struct.tst	Tue Oct 13 11:40:05 2015 +0100
+++ b/test/struct.tst	Tue Oct 13 09:55:46 2015 -0700
@@ -57,21 +57,14 @@
 %! s.a = 2;
 %! assert (isfield (s, 2) == 0);
 
-%!assert (!(isstruct (1)))
-
-%!assert (!(isstruct ([1, 2])))
-
-%!assert (!(isstruct ([])))
-
-%!assert (!(isstruct ([1, 2; 3, 4])))
-
-%!assert (!(isstruct ("t")))
-
-%!assert (!(isstruct ("test")))
-
-%!assert (!(isstruct (["test"; "ing"])))
-
-%!assert (!(isstruct ({1})))
+%!assert (isstruct (1), false)
+%!assert (isstruct ([1, 2]), false)
+%!assert (isstruct ([]), false)
+%!assert (isstruct ([1, 2; 3, 4]), false)
+%!assert (isstruct ("t"), false)
+%!assert (isstruct ("test"), false)
+%!assert (isstruct (["test"; "ing"]), false)
+%!assert (isstruct ({1}), false)
 
 %!test
 %! s.a = 1;
@@ -238,6 +231,14 @@
 %! s(3).foo = 42;
 %! assert (s(3), struct ("foo", 42));
 
+## test assigning to multi-dim struct with trailing singleton dimensions,
+## Bug #35841.
+%!test
+%! a(1,1,1).b(1) = 1;
+%! a(1,1,1).b(1) = 2;
+%! a(1,1,:).b(1) = 3;
+%! assert (a(1,1,1).b(1) == 3);
+
 %!error id=Octave:index-out-of-bounds
 %! s = resize (struct (),3,2);
 %! s(3).foo = 42;