changeset 12261:1860ce6c30d0 release-3-4-x

fix another bug in class assignment to undefined object with index
author John W. Eaton <jwe@octave.org>
date Thu, 27 Jan 2011 06:16:50 -0500
parents 5f1bb7aa3a3a
children b22c00315df5
files src/ChangeLog src/ov-struct.cc
diffstat 2 files changed, 26 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
+2011-01-27  John W. Eaton  <jwe@octave.org>
+
+	* ov-struct.cc (octave_struct::subsasgn,
+	octave_scalar_struct::subsasgn): Call undef_subsasgn on object
+	returned by octave_value::empty_conv if LHS is initially undefined.
+	Bug #32242.
+
 2011-01-27  John W. Eaton  <jwe@octave.org>
 
 	* input.cc (input_event_hook): Fix incorrect use of iterator.
@@ -23,7 +30,7 @@
 	* ov-class.h, ov-class.cc (octave_class::undef_subsasgn,
 	octave_class::subsasgn_common): New functions.
 	* ov-base.h, ov-base.cc (octave_base_value::subsasgn): If
-	undefined, undef_subsasgn on object returned by
+	undefined, call undef_subsasgn on object returned by
 	octave_value::empty_conv.
 	(octave_base_value::undef_subsasgn): New virtual function.
 	(octave_base_value::subsasgn): Only handle case of undefined
--- a/src/ov-struct.cc
+++ b/src/ov-struct.cc
@@ -328,7 +328,9 @@
                       {
                         octave_value& tmp = tmpc(0);
 
-                        if (! tmp.is_defined () || tmp.is_zero_by_zero ())
+                        bool orig_undefined = tmp.is_undefined ();
+
+                        if (orig_undefined || tmp.is_zero_by_zero ())
                           {
                             tmp = octave_value::empty_conv (next_type, rhs);
                             tmp.make_unique (); // probably a no-op.
@@ -338,7 +340,9 @@
                           tmp.make_unique (1);
 
                         if (! error_state)
-                          t_rhs = tmp.subsasgn (next_type, next_idx, rhs);
+                          t_rhs = (orig_undefined
+                                   ? tmp.undef_subsasgn (next_type, next_idx, rhs)
+                                   : tmp.subsasgn (next_type, next_idx, rhs));
                       }
                     else
                       gripe_indexed_cs_list ();
@@ -378,7 +382,9 @@
                   {
                     octave_value& tmp = tmpc(0);
 
-                    if (! tmp.is_defined () || tmp.is_zero_by_zero ())
+                    bool orig_undefined = tmp.is_undefined ();
+
+                    if (orig_undefined || tmp.is_zero_by_zero ())
                       {
                         tmp = octave_value::empty_conv (next_type, rhs);
                         tmp.make_unique (); // probably a no-op.
@@ -388,7 +394,9 @@
                       tmp.make_unique (1);
 
                     if (! error_state)
-                      t_rhs = tmp.subsasgn (next_type, next_idx, rhs);
+                      t_rhs = (orig_undefined
+                               ? tmp.undef_subsasgn (next_type, next_idx, rhs)
+                               : tmp.subsasgn (next_type, next_idx, rhs));
                   }
                 else
                   gripe_indexed_cs_list ();
@@ -1244,7 +1252,9 @@
 
           if (! error_state)
             {
-              if (! tmp.is_defined () || tmp.is_zero_by_zero ())
+              bool orig_undefined = tmp.is_undefined ();
+
+              if (orig_undefined || tmp.is_zero_by_zero ())
                 {
                   tmp = octave_value::empty_conv (next_type, rhs);
                   tmp.make_unique (); // probably a no-op.
@@ -1254,7 +1264,9 @@
                 tmp.make_unique (1);
 
               if (! error_state)
-                t_rhs = tmp.subsasgn (next_type, next_idx, rhs);
+                t_rhs = (orig_undefined
+                         ? tmp.undef_subsasgn (next_type, next_idx, rhs)
+                         : tmp.subsasgn (next_type, next_idx, rhs));
             }
         }