list indexing errors

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

list indexing errors

Paul Kienzle
The following code crashes octave:

 > x=list(1,2,3)
 > x(2)

I tried it on 2.1.52 and 2.1.57 debian, and on 2.1.55 mac os x.

This is something I noticed when trying to see if reverse() could
be replaced by a simple m-file:

        x=list(1,2,3)
        rev = x(end:-1:1)

I don't know of any code which is affected by this.

Paul Kienzle
[hidden email]


Reply | Threaded
Open this post in threaded view
|

list indexing errors

John W. Eaton-6
On 18-Mar-2004, Paul Kienzle <[hidden email]> wrote:

| The following code crashes octave:
|
|  > x=list(1,2,3)
|  > x(2)

Please try the following patch.

Thanks,

jwe


src/ChangeLog:

2004-03-19  John W. Eaton  <[hidden email]>

        * ov-list.cc (octave_list::subsref): Correctly create return value.
        Return comma-separate list if {-style indexing extracts more than
        one value.


Index: src/ov-list.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/ov-list.cc,v
retrieving revision 1.37
diff -u -r1.37 ov-list.cc
--- a/src/ov-list.cc 12 Mar 2004 19:13:02 -0000 1.37
+++ b/src/ov-list.cc 19 Mar 2004 22:29:17 -0000
@@ -76,7 +76,9 @@
   {
     idx_vector i = tmp_idx (0).index_vector ();
 
-    retval = octave_list (data.index (i));
+    Cell tmp = data.index (i);
+
+    retval = octave_value (new octave_list (tmp));
   }
  else
   error ("only one index allowed for lists");
@@ -95,6 +97,8 @@
 
     if (tmp.length () == 1)
       retval = tmp(0);
+    else
+      retval = octave_value (tmp, true);
   }
  else
   error ("only one index allowed for lists");