]> git.imager.perl.org - imager.git/commitdiff
Imager::Color set_internal is now simpler
authorTony Cook <tony@develop-help.com>
Mon, 31 Dec 2018 11:34:06 +0000 (22:34 +1100)
committerTony Cook <tony@develop-help.com>
Mon, 31 Dec 2018 11:34:06 +0000 (22:34 +1100)
Coverity complained that ICL_set_internal() could leak here, but
that's only possible with a NULL pointer PTROBJ, which would break
in many other ways.

Changes
Imager.xs
t/100-base/020-color.t

diff --git a/Changes b/Changes
index 27b0f412211936d91ff188adb2f2b15f8dea25f7..e115b31b5efaf6835b10f3cb129834f309fbe627 100644 (file)
--- a/Changes
+++ b/Changes
@@ -26,6 +26,11 @@ Coverity finally finished a build, fix a few problems:
    Negative values (which Coverity didn't complain about) could also
    cause problems.
 
+ - the Imager::Color set_internal() interal method no longer
+   calls the over-complicated ICL_set_internal() (which is retained
+   only for the old API.)  Coverity complained that this leaked, but
+   this could only occur with an invalid (NULL pointer) color object.
+
 Imager 1.008 - 31 Dec 2018
 ============
 
index a69fec9eb3c6a1bfc72aeec4cf1b577c13d011a6..9307d16a3ce870e37d7f5f1c00fd58fdcd931243 100644 (file)
--- a/Imager.xs
+++ b/Imager.xs
@@ -1105,7 +1105,10 @@ ICL_set_internal(cl,r,g,b,a)
                unsigned char     b
                unsigned char     a
           PPCODE:
-              ICL_set_internal(cl, r, g, b, a);
+              cl->rgba.r = r;
+              cl->rgba.g = g;
+              cl->rgba.b = b;
+              cl->rgba.a = a;
               EXTEND(SP, 1);
               PUSHs(ST(0));
 
index b6d4f061379fae05c65fd7d2d95ba954d85cf137..cfc2bc3f5005ecffbf1d9f713f3411fd284c98a1 100644 (file)
@@ -7,7 +7,7 @@
 # Change 1..1 below to 1..last_test_to_print .
 # (It may become useful if the test is moved to ./t subdirectory.)
 
-use Test::More tests => 73;
+use Test::More;
 
 use Imager;
 use Imager::Test qw(is_fcolor3 is_fcolor4 is_color4);
@@ -30,8 +30,8 @@ for (1..1000) {
 my $fail;
 for (@foo) {
   Imager::Color::set_internal($_, 128, 128, 128, 128) == $_ or ++$fail;
-  Imager::Color::set_internal($_, 128, 128, 128, 128) == $_ or ++$fail;
-  test_col($_, 128, 128, 128, 128) or ++$fail;
+  Imager::Color::set_internal($_, 128, 129, 130, 131) == $_ or ++$fail;
+  test_col($_, 128, 129, 130, 131) or ++$fail;
 }
 ok(!$fail, 'consitency check');
 
@@ -269,6 +269,8 @@ is_color4(Imager::Color->new(builtin=>'black'), 0, 0, 0, 255, 'builtin black');
   is($v,0,'black value');
 }
 
+done_testing();
+
 sub test_col {
   my ($c, $r, $g, $b, $a) = @_;
   unless ($c) {