]> git.imager.perl.org - imager.git/commitdiff
- the setcolors() had a fencepost error making it impossible to
authorTony Cook <tony@develop=help.com>
Wed, 11 May 2005 14:37:29 +0000 (14:37 +0000)
committerTony Cook <tony@develop=help.com>
Wed, 11 May 2005 14:37:29 +0000 (14:37 +0000)
  use it to set the last color in the palette.
  http://rt.cpan.org/NoAuth/Bug.html?id=12676

Changes
palimg.c
t/t023palette.t

diff --git a/Changes b/Changes
index f7675260bd3ae203435b7db606647fe8ac8cea98..08524412eca19ff05693f057d570aa10237235ce 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1091,6 +1091,9 @@ Revision history for Perl extension Imager.
   parameter wasn't passed to the read() method would produce
   diagnostics on stdout, precluding use in web applications.  Silenced
   it.
+- the setcolors() had a fencepost error making it impossible to 
+  use it to set the last color in the palette.
+  http://rt.cpan.org/NoAuth/Bug.html?id=12676
 
 =================================================================
 
index b655963eb161894e68e480f15777635848c603a1..1667238ec57b0d3bf94f47044526a3a48122be1e 100644 (file)
--- a/palimg.c
+++ b/palimg.c
@@ -537,7 +537,7 @@ static int i_maxcolors_p(i_img *im) {
 =cut
 */
 static int i_setcolors_p(i_img *im, int index, i_color *colors, int count) {
-  if (index >= 0 && count >= 1 && index + count < PALEXT(im)->count) {
+  if (index >= 0 && count >= 1 && index + count <= PALEXT(im)->count) {
     while (count) {
       PALEXT(im)->pal[index++] = *colors++;
       --count;
index 65e38c9aab604f348c411a2a08a129c8aea00b8e..315782173fcd27ba611ee5830cccac5d12e77bcb 100644 (file)
@@ -2,7 +2,7 @@
 # some of this is tested in t01introvert.t too
 use strict;
 use lib 't';
-use Test::More tests => 59;
+use Test::More tests => 62;
 BEGIN { use_ok("Imager"); }
 
 my $img = Imager->new(xsize=>50, ysize=>50, type=>'paletted');
@@ -190,6 +190,17 @@ cmp_ok(Imager->errstr, '=~', qr/Channels must be positive and <= 4/,
   cmp_ok($warning, '=~', 't023palette\\.t', "correct file");
 }
 
+{ # http://rt.cpan.org/NoAuth/Bug.html?id=12676
+  # setcolors() has a fencepost error
+  my $img = Imager->new(xsize=>10, ysize=>10, type=>'paletted');
+
+  is($img->addcolors(colors=>[ $black, $red ]), "0 but true",
+     "add test colors");
+  ok($img->setcolors(start=>1, colors=>[ $green ]), "set the last color");
+  ok(!$img->setcolors(start=>2, colors=>[ $black ]), 
+     "set after the last color");
+}
+
 sub coloreq {
   my ($left, $right, $comment) = @_;