Code

Collectd::Unixsock: Improved error handling in putval().
authorSebastian Harl <sh@tokkee.org>
Thu, 19 Feb 2009 10:03:01 +0000 (11:03 +0100)
committerSebastian Harl <sh@tokkee.org>
Thu, 19 Feb 2009 12:51:59 +0000 (13:51 +0100)
bindings/perl/Collectd/Unixsock.pm

index eb6e389e34b823d1df792f61f854c3ae183688eb..440317840a07a7de1763f175c0d9e3a44a810e8c 100644 (file)
@@ -287,7 +287,21 @@ sub putval
        }
        else
        {
-               my $time = $args{'time'} ? $args{'time'} : time ();
+               my $time;
+
+               if ("ARRAY" ne ref ($args{'values'}))
+               {
+                       cluck ("Invalid `values' argument (expected an array ref)");
+                       return;
+               }
+
+               if (! scalar @{$args{'values'}})
+               {
+                       cluck ("Empty `values' array");
+                       return;
+               }
+
+               $time = $args{'time'} ? $args{'time'} : time ();
                $values = join (':', $time, map { defined ($_) ? $_ : 'U' } (@{$args{'values'}}));
        }