changeset 20425:41d19a6ef55a

Allow assignment of an empty variable to an empty indexing slice (bug #45467). * Array.cc (Array<T>::assign): For 2-D case, check that neither the LHS or RHS is empty before calling gripe_assignment_dimension_mismatch(). * Array.cc (Array<T>::assign): For N-D case, check that neither the LHS or RHS is empty before calling gripe_assignment_dimension_mismatch().
author Lachlan Andrew <lachlanbis@gmail.com>
date Fri, 24 Jul 2015 14:40:18 -0700
parents 6bc09e953927
children 39721c09691b
files liboctave/array/Array.cc
diffstat 1 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/array/Array.cc	Fri Jul 24 10:40:05 2015 -0400
+++ b/liboctave/array/Array.cc	Fri Jul 24 14:40:18 2015 -0700
@@ -1183,6 +1183,7 @@
     gripe_invalid_assignment_size ();
 }
 
+// Assignment to a 2-dimensional array
 template <class T>
 void
 Array<T>::assign (const idx_vector& i, const idx_vector& j,
@@ -1281,10 +1282,12 @@
             }
         }
     }
-  else
+  // any empty RHS can be assigned to an empty LHS
+  else if ((il != 0 && jl != 0) || (rhdv(0) != 0 && rhdv(1) != 0))
     gripe_assignment_dimension_mismatch ();
 }
 
+// Assignment to a multi-dimensional array
 template <class T>
 void
 Array<T>::assign (const Array<idx_vector>& ia,
@@ -1384,7 +1387,19 @@
             }
         }
       else
-        gripe_assignment_dimension_mismatch ();
+        {
+          // dimension mismatch, unless LHS and RHS both empty
+          bool lhsempty, rhsempty;
+          lhsempty = rhsempty = false;
+          for (int i = 0; i < ial; i++)
+            {
+              octave_idx_type l = ia(i).length (rdv(i));
+              lhsempty = lhsempty || (l == 0);
+              rhsempty = rhsempty || (rhdv(j++) == 0);
+            }
+          if (! lhsempty || ! rhsempty)
+            gripe_assignment_dimension_mismatch ();
+        }
     }
 }