[perl-Gtk2] Gtk2::Gdk::Pixbuf->save(): check for even number of key/value args



commit ec5aa699ab8b256ef53169a1590531f0979f9515
Author: Kevin Ryde <user42 zip com au>
Date:   Tue Dec 7 22:35:05 2010 +0100

    Gtk2::Gdk::Pixbuf->save(): check for even number of key/value args
    
    https://bugzilla.gnome.org/show_bug.cgi?id=621259

 NEWS            |    3 ++-
 t/GdkPixbuf.t   |    8 +++++++-
 xs/GdkPixbuf.xs |    6 +++++-
 3 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/NEWS b/NEWS
index 7876ea4..f2865ad 100644
--- a/NEWS
+++ b/NEWS
@@ -5,7 +5,8 @@ Overview of changes in the next unstable release
 * Allow Gtk2::Buildable implementations to return undef from
   GET_INTERNAL_CHILD.
 * Ensure that the option strings passed to Gtk2::Gdk::Pixbuf->save() are
-  upgraded to utf8 if necessary.
+  upgraded to utf8 if necessary.  Also, complain if an odd number of key/value
+  args is given.
 
 Overview of changes in Gtk2 1.230
 =================================
diff --git a/t/GdkPixbuf.t b/t/GdkPixbuf.t
index a0a92b6..5cdc459 100644
--- a/t/GdkPixbuf.t
+++ b/t/GdkPixbuf.t
@@ -1,7 +1,7 @@
 #!/usr/bin/env perl
 use strict;
 use warnings;
-use Gtk2::TestHelper tests => 110, noinit => 1;
+use Gtk2::TestHelper tests => 111, noinit => 1;
 
 my $show = 0;
 
@@ -212,6 +212,12 @@ unlink $filename;
 
 
 $filename = 'testsave.png';
+eval {
+  $pixbuf->save ($filename, 'png',
+		 'key_arg_without_value_arg');
+};
+like ($@, qr/odd number of arguments detected/);
+
 my $mtime = scalar localtime;
 my $desc = 'Something really cool';
 $pixbuf->save ($filename, 'png',
diff --git a/xs/GdkPixbuf.xs b/xs/GdkPixbuf.xs
index 23be15b..88ecb5e 100644
--- a/xs/GdkPixbuf.xs
+++ b/xs/GdkPixbuf.xs
@@ -643,7 +643,11 @@ gdk_pixbuf_save (pixbuf, filename, type, ...)
 	/* collect key/val pairs from the argument stack and 
 	 * call gdk_pixbuf_savev */
 #define FIRST_KEY 3
-	nkeys = (items - FIRST_KEY) / 2;
+	nkeys = items - FIRST_KEY;
+	if (nkeys % 2)
+		croak ("gdk_pixbuf_save expects options as key => value pairs "
+		       "(odd number of arguments detected)");
+	nkeys /= 2;
 	/* always allocate them.  doesn't hurt.  always one longer for the
 	 * null-terminator, which is set by g_new0. */
 	option_keys = g_new0 (char *, nkeys + 1);



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