]> git.imager.perl.org - imager.git/commitdiff
[rt #68993] check the number of conv coefficients is positive
authorTony Cook <tony@develop-help.com>
Sat, 15 Oct 2011 01:48:26 +0000 (12:48 +1100)
committerTony Cook <tony@develop-help.com>
Sat, 15 Oct 2011 01:48:26 +0000 (12:48 +1100)
Changes
conv.im
t/t61filters.t

diff --git a/Changes b/Changes
index fba644eafd12c0ee782cccae013811495ee849d9..a57f364f002d32d764d66452619ce921ba7ff7eb 100644 (file)
--- a/Changes
+++ b/Changes
@@ -53,6 +53,9 @@ Bug fixes:
  - updated the Thanks list in README
    https://rt.cpan.org/Ticket/Display.html?id=71607
 
  - updated the Thanks list in README
    https://rt.cpan.org/Ticket/Display.html?id=71607
 
+ - check there's at least one coefficient for the convolution filter
+   https://rt.cpan.org/Ticket/Display.html?id=68993
+
 Imager 0.85_01 - 10 Oct 2011
 ==============
 
 Imager 0.85_01 - 10 Oct 2011
 ==============
 
diff --git a/conv.im b/conv.im
index b766d7eb7cc2495aae4bdb9dd9936737240c19e6..f02db85633db7824087c8b21d179218143c591d5 100644 (file)
--- a/conv.im
+++ b/conv.im
@@ -22,6 +22,11 @@ i_conv(i_img *im, const double *coeff,int len) {
 
   mm_log((1,"i_conv(im %p, coeff %p, len %d)\n",im,coeff,len));
   i_clear_error();
 
   mm_log((1,"i_conv(im %p, coeff %p, len %d)\n",im,coeff,len));
   i_clear_error();
+
+  if (len < 1) {
+    i_push_error(0, "there must be at least one coefficient");
+    return 0;
+  }
  
   center=(len-1)/2;
 
  
   center=(len-1)/2;
 
index b9e0005466dcc88b42f876eed8c4c2e6761045e4..84bdc447a83cc18d8af36587ec8e1582705263db 100644 (file)
@@ -1,7 +1,7 @@
 #!perl -w
 use strict;
 use Imager qw(:handy);
 #!perl -w
 use strict;
 use Imager qw(:handy);
-use Test::More tests => 113;
+use Test::More tests => 116;
 
 -d "testout" or mkdir "testout";
 
 
 -d "testout" or mkdir "testout";
 
@@ -23,6 +23,15 @@ test($imbase, {type=>'contrast', intensity=>0.5},
 test($imbase, {type=>'conv', coef=>[ 0.3, 1, 0.3, ], },
      'testout/t61_conv_blur.ppm');
 
 test($imbase, {type=>'conv', coef=>[ 0.3, 1, 0.3, ], },
      'testout/t61_conv_blur.ppm');
 
+{
+  my $work = $imbase->copy;
+  ok(!Imager::i_conv($work->{IMG}, []), "conv should fail with empty array");
+  ok(!$work->filter(type => 'conv', coef => []),
+     "check the conv OO intergave too");
+  is($work->errstr, "there must be at least one coefficient",
+     "check conv error message");
+}
+
 {
   my $work8 = $imbase->copy;
   ok(!$work8->filter(type => "conv", coef => "ABC"),
 {
   my $work8 = $imbase->copy;
   ok(!$work8->filter(type => "conv", coef => "ABC"),