perl-Glib r1067 - in trunk: . t



Author: tsch
Date: Tue Feb  3 19:24:42 2009
New Revision: 1067
URL: http://svn.gnome.org/viewvc/perl-Glib?rev=1067&view=rev

Log:
Make sure that messages with % chars in them make it through Glib::log() and
friends safely.


Modified:
   trunk/ChangeLog
   trunk/GLog.xs
   trunk/t/a.t

Modified: trunk/GLog.xs
==============================================================================
--- trunk/GLog.xs	(original)
+++ trunk/GLog.xs	Tue Feb  3 19:24:42 2009
@@ -235,7 +235,7 @@
 
 void g_log (class, gchar_ornull * log_domain, SV * log_level, const gchar *message)
     CODE:
-	g_log (log_domain, SvGLogLevelFlags (log_level), message);
+	g_log (log_domain, SvGLogLevelFlags (log_level), "%s", message);
 
 MODULE = Glib::Log	PACKAGE = Glib::Log	PREFIX = g_log_
 
@@ -292,7 +292,7 @@
 		case 2: flags = G_LOG_LEVEL_CRITICAL; break;
 		case 3: flags = G_LOG_LEVEL_WARNING; break;
 	}
-	g_log (domain, flags, message);
+	g_log (domain, flags, "%s", message);
 
 ##
 ## these are not needed -- perl's print() and warn() do the job.

Modified: trunk/t/a.t
==============================================================================
--- trunk/t/a.t	(original)
+++ trunk/t/a.t	Tue Feb  3 19:24:42 2009
@@ -20,7 +20,7 @@
 	# have to bail out.
 	plan skip_all => "g_log doubles messages by accident on 64-bit platforms";
 } else {
-	plan tests => 11;
+	plan tests => 12;
 }
 
 package Foo;
@@ -30,7 +30,7 @@
 
 package main;
 
-$SIG{__WARN__} = sub { ok(1, "in __WARN__: $_[0]"); };
+$SIG{__WARN__} = sub { chomp (my $msg = $_[0]); ok(1, "in __WARN__: $msg"); };
 #$SIG{__DIE__} = sub { ok(1, 'in __DIE__'); };
 
 Glib->message (undef, 'whee message');
@@ -90,6 +90,19 @@
 #print "$ \n";
 #}
 
+# Check that messages with % chars make it through unaltered and don't cause
+# crashes
+{
+	my $id = Glib::Log->set_handler (
+		__PACKAGE__,
+		qw/debug/,
+		sub { is($_[2], '%s %d %s', 'a message with % chars'); });
+
+	Glib->log (__PACKAGE__, qw/debug/, '%s %d %s');
+
+	Glib::Log->remove_handler (__PACKAGE__, $id);
+}
+
 Glib::Log->set_fatal_mask (__PACKAGE__, [qw/ warning message /]);
 Glib::Log->set_always_fatal ([qw/ info debug /]);
 



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