# New Ticket Created by  Tony Payne 
# Please include the string:  [perl #822]
# in the subject line of all future correspondence about this issue. 
# <URL: http://bugs6.perl.org/rt2/Ticket/Display.html?id=822 >



I set off to try to increase the coverage of parrot_coverage and right away
tripped into a segfault in intqueue if you try to dequeue an empty queue.  
This patch fixes the segfault and adds a test for it.

++t


-- attachment  1 ------------------------------------------------------
url: http://bugs6.perl.org/rt2/attach/3866/3577/55bba3/intq.diff

Index: t/pmc/pmc.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/pmc.t,v
retrieving revision 1.32
diff -u -u -r1.32 pmc.t
--- t/pmc/pmc.t	4 Jul 2002 00:49:04 -0000	1.32
+++ t/pmc/pmc.t	16 Jul 2002 01:42:42 -0000
@@ -1,6 +1,6 @@
 #! perl -w
 
-use Parrot::Test tests => 59;
+use Parrot::Test tests => 60;
 use Test::More;
 
 my $fp_equality_macro = <<'ENDOFMACRO';
@@ -1258,6 +1258,15 @@
 ok 3
 ok 4
 OUTPUT
+
+output_is(<<CODE, <<OUTPUT, "IntQueue test");
+	new P0,.IntQueue
+        set I0, P0
+        end
+CODE
+*** dequeue tried to dequeue empty bucket
+OUTPUT
+
 
 output_is(<<CODE, <<OUTPUT, "mul_p_p, PerlInt");
 @{[ $fp_equality_macro ]}
Index: classes/intqueue.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/intqueue.pmc,v
retrieving revision 1.10
diff -u -u -r1.10 intqueue.pmc
--- classes/intqueue.pmc	11 Jun 2002 21:04:58 -0000	1.10
+++ classes/intqueue.pmc	16 Jul 2002 01:42:42 -0000
@@ -49,20 +49,24 @@
 }
 
 static INTVAL dequeue ( CONTAINER* container ) {
-  INTVAL value = container->tail->value;
+  INTVAL value;
   if(container->head != container->tail) {
     BUCKET* cur = container->tail;
+    value = container->tail->value;
     container->tail = container->tail->prev;
     container->tail->next = NULL;
     free(cur);
   }
   else if(container->head != NULL) {
+    value = container->tail->value;
     free(container->head);
     container->head = NULL;
     container->tail = NULL;
   }
   else {
     fprintf(stderr,"*** dequeue tried to dequeue empty bucket\n");
+    /* XXX: Should raise an exception */
+    return 0;
   }
   return value;
 }

Reply via email to