[svn:parrot] r49487 - in trunk: src/pmc t/pmc

dukeleto at svn.parrot.org dukeleto at svn.parrot.org
Sun Oct 10 05:38:02 UTC 2010


Author: dukeleto
Date: Sun Oct 10 05:38:01 2010
New Revision: 49487
URL: https://trac.parrot.org/parrot/changeset/49487

Log:
[pmc] Fix coredump in ByteBuffer when initialized with a negative size and add a test

Modified:
   trunk/src/pmc/bytebuffer.pmc
   trunk/t/pmc/bytebuffer.t

Modified: trunk/src/pmc/bytebuffer.pmc
==============================================================================
--- trunk/src/pmc/bytebuffer.pmc	Sat Oct  9 14:30:46 2010	(r49486)
+++ trunk/src/pmc/bytebuffer.pmc	Sun Oct 10 05:38:01 2010	(r49487)
@@ -71,6 +71,9 @@
 
     VTABLE void init_int(INTVAL initial_size) {
         unsigned char *content;
+        if (initial_size < 0)
+            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
+                _("ByteBuffer: Cannot set buffer size to a negative number (%d)"), initial_size);
         STATICSELF.init();
         SET_ATTR_size(INTERP, SELF, initial_size);
         SET_ATTR_allocated_size(INTERP, SELF, initial_size);

Modified: trunk/t/pmc/bytebuffer.t
==============================================================================
--- trunk/t/pmc/bytebuffer.t	Sat Oct  9 14:30:46 2010	(r49486)
+++ trunk/t/pmc/bytebuffer.t	Sun Oct 10 05:38:01 2010	(r49487)
@@ -22,7 +22,7 @@
 
 .sub 'main' :main
     .include 'test_more.pir'
-    plan(37)
+    plan(38)
 
     test_init()
     test_set_string()
@@ -65,6 +65,14 @@
     n = elements bb
     is(n, 42, "size of a new buffer with initial size is correct")
 
+    push_eh handler
+    bb = new ['ByteBuffer'], -1
+handler:
+    pop_eh
+    ok(1,"Creating a negative-sized ByteBuffer throws an exception")
+    goto done
+
+  done:
 .end
 
 .sub test_set_string


More information about the parrot-commits mailing list