RT #107900 Panic due to attempt to extend stack by negative amount
authorA. Sinan Unur <nanis@cpan.org>
Wed, 21 Oct 2015 19:41:24 +0000 (15:41 -0400)
committerTony Cook <tony@develop-help.com>
Wed, 4 Nov 2015 11:04:01 +0000 (22:04 +1100)
See https://rt.cpan.org/Public/Bug/Display.html?id=107900

See also

http://www.cpantesters.org/distro/I/Imager.html#Imager-1.003?grade=1&perlmat=3&patches=2&oncpan=2&distmat=2&perlver=5.23.4&osname=ALL&version=1.003

Fix by only EXTENDing return stack and pushing values if returned
col_cnt is positive.

Imager.xs

index 6a205ba..6803f04 100644 (file)
--- a/Imager.xs
+++ b/Imager.xs
@@ -2674,12 +2674,17 @@ i_get_anonymous_color_histo(im, maxc = 0x40000000)
         int col_cnt;
     PPCODE:
        col_cnt = i_get_anonymous_color_histo(im, &col_usage, maxc);
+    if (col_cnt > 0) {
         EXTEND(SP, col_cnt);
         for (i = 0; i < col_cnt; i++)  {
             PUSHs(sv_2mortal(newSViv( col_usage[i])));
         }
         myfree(col_usage);
         XSRETURN(col_cnt);
+    }
+    else {
+        XSRETURN_EMPTY;
+    }
 
 
 void