Author: cotto
Date: Sat Jul 26 20:46:23 2008
New Revision: 29786

Modified:
   trunk/src/intlist.c
   trunk/t/pmc/intlist.t

Log:
[intlist] make intlist_get correctly check return list_get's return value


Modified: trunk/src/intlist.c
==============================================================================
--- trunk/src/intlist.c (original)
+++ trunk/src/intlist.c Sat Jul 26 20:46:23 2008
@@ -306,10 +306,11 @@
 INTVAL
 intlist_get(PARROT_INTERP, ARGMOD(IntList *list), INTVAL idx)
 {
-    /* XXX list_get can return NULL RT #48367 */
     void * const ret = list_get(interp, (List *)list, idx, enum_type_INTVAL);
-    const INTVAL retval = ret == (void *)-1 ? 0 : *(INTVAL *)ret;
-    return retval;
+    if (ret) 
+        return *(INTVAL *)ret;
+
+    return (INTVAL)0;
 }
 
 /*

Modified: trunk/t/pmc/intlist.t
==============================================================================
--- trunk/t/pmc/intlist.t       (original)
+++ trunk/t/pmc/intlist.t       Sat Jul 26 20:46:23 2008
@@ -6,7 +6,7 @@
 use warnings;
 use lib qw( . lib ../lib ../../lib );
 use Test::More;
-use Parrot::Test tests => 8;
+use Parrot::Test tests => 9;
 
 =head1 NAME
 
@@ -168,6 +168,18 @@
 I need a shower.
 OUTPUT
 
+pasm_output_is( <<'CODE', <<'OUTPUT', "out of bounds" );
+    #shouldn't cause a segfault
+    new P0, 'IntList'
+    set P0, 1
+    set I0, P0[25]
+    set S0, "didn't segfault\n"
+    print S0
+    end
+CODE
+didn't segfault
+OUTPUT
+
 pasm_output_is( <<'CODE', <<'OUTPUT', "direct access 2" );
     new P0, 'IntList'
     set I10, 1100000

Reply via email to