[perl-Gtk2] Gtk2::Gdk::Region->spans_intersect_foreach: verify number of args



commit 9b7373f172d73c54a6593bedae70c63c5bdfd6b2
Author: Kevin Ryde <user42 zip com au>
Date:   Thu Nov 25 09:25:37 2010 +1100

    Gtk2::Gdk::Region->spans_intersect_foreach: verify number of args
    
    Correct the croak() message, and check that the arrayref has a multiple 3
    elements instead of silently ignoring extras.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=635120

 t/GdkRegion.t   |   17 +++++++++++++++--
 xs/GdkRegion.xs |    7 +++++--
 2 files changed, 20 insertions(+), 4 deletions(-)
---
diff --git a/t/GdkRegion.t b/t/GdkRegion.t
index 8120441..a142fd1 100644
--- a/t/GdkRegion.t
+++ b/t/GdkRegion.t
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 use strict;
-use Gtk2::TestHelper tests => 23, noinit => 1;
+use Gtk2::TestHelper tests => 29, noinit => 1;
 
 # $Id$
 
@@ -51,6 +51,19 @@ $region -> spans_intersect_foreach([24, 43, 5,
   is($data, "bla");
 }, "bla");
 
+ok (! eval { $region->spans_intersect_foreach([1], 1, sub {}); 1 },
+      'spans_intersect_foreach() 1 coord - expect error');
+ok (! eval { $region->spans_intersect_foreach([1,2], 1, sub {}); 1 },
+      'spans_intersect_foreach() 2 coords - expect error');
+ok (  eval { $region->spans_intersect_foreach([1,2,3], 1, sub {}); 1 },
+      'spans_intersect_foreach() 3 coords - expect good');
+ok (! eval { $region->spans_intersect_foreach([1,2,3,4], 1, sub {}); 1 },
+      'spans_intersect_foreach() 4 coords - expect error');
+ok (! eval { $region->spans_intersect_foreach([1,2,3,4,5], 1, sub {}); 1 },
+      'spans_intersect_foreach() 5 coords - expect error');
+ok (  eval { $region->spans_intersect_foreach([1,2,3,4,5,6], 1, sub {}); 1 },
+      'spans_intersect_foreach() 6 coords - expect good');
+
 $region -> offset(5, 5);
 $region -> shrink(5, 5);
 $region -> union_with_rect($rectangle_two);
@@ -72,5 +85,5 @@ SKIP: {
 
 __END__
 
-Copyright (C) 2003 by the gtk2-perl team (see the file AUTHORS for the
+Copyright (C) 2003, 2010 by the gtk2-perl team (see the file AUTHORS for the
 full list).  See LICENSE for more information.
diff --git a/xs/GdkRegion.xs b/xs/GdkRegion.xs
index 1eeec28..54ec46c 100644
--- a/xs/GdkRegion.xs
+++ b/xs/GdkRegion.xs
@@ -253,10 +253,13 @@ gdk_region_spans_intersect_foreach (region, spans_ref, sorted, func, data=NULL)
 	GPerlCallback * callback;
     CODE:
 	if (!gperl_sv_is_array_ref (spans_ref))
-		croak ("span list has to be a reference to an array of GdkPoint's");
+		croak ("span list must be an arrayref of triples [ $x,$y,$width,$x,$y,$width,...]");
 
 	array = (AV *) SvRV (spans_ref);
-	n_spans = (av_len (array) + 1) / 3;
+	n_spans = av_len (array) + 1;
+	if ((n_spans % 3) != 0)
+		croak ("span list not a multiple of 3");
+	n_spans /= 3;
 	spans = g_new0 (GdkSpan, n_spans);
 
 	for (i = 0; i < n_spans; i++) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]