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 eb6e389..4403178 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'}}));
        }