From: Tony Cook Date: Thu, 17 Sep 2009 12:26:22 +0000 (+0000) Subject: - an integer division meant that preview scaling to below 1 pixel X-Git-Tag: Imager-0.71~9 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/b3afeed5d907587a0ba5b491f2f5420375edd185 - an integer division meant that preview scaling to below 1 pixel wide or high (which isn't too useful anyway) was calculating using NaNs on most platforms, and causing an exception on others. Thanks to David Cantrell for producing a backtrace of the crash on his Alpha-NetBSD CPAN test box which made it possible to track this down. --- diff --git a/Changes b/Changes index fe2db308..0e8d74cb 100644 --- a/Changes +++ b/Changes @@ -12,6 +12,13 @@ Bug fixes: pointer dereference Thanks to Krzysztof Wojtaś for the test data and fix for this. + - an integer division meant that preview scaling to below 1 pixel + wide or high (which isn't too useful anyway) was calculating using + NaNs on most platforms, and causing an exception on others. + Thanks to David Cantrell for producing a backtrace of the crash on + his Alpha-NetBSD CPAN test box which made it possible to track this + down. + Imager 0.69 - 08 Sep 2009 =========== diff --git a/Makefile.PL b/Makefile.PL index c05d5b38..291a58c5 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -41,6 +41,7 @@ my @libpaths; # places to look for libraries my $noexif; # non-zero to disable EXIF parsing of JPEGs my $no_gif_set_version; # disable calling EGifSetGifVersion my $coverage; # build for coverage testing +my $assert; # build with assertions GetOptions("help" => \$help, "enable=s" => \@enable, "disable=s" => \@disable, @@ -50,7 +51,12 @@ GetOptions("help" => \$help, "nolog" => \$NOLOG, "noexif" => \$noexif, "nogifsetversion" => \$no_gif_set_version, - 'coverage' => \$coverage); + 'coverage' => \$coverage, + "assert|a" => \$assert); + +if ($ENV{AUTOMATED_TESTING}) { + $assert = 1; +} if ($VERBOSE) { print "Verbose mode\n"; @@ -69,6 +75,10 @@ else { push @defines, [ IMAGER_LOG => 1, "Logging system" ]; } +if ($assert) { + push @defines, [ IM_ASSERT => 1, "im_assert() are effective" ]; +} + if ($DEBUG_MALLOC) { push @defines, [ IMAGER_DEBUG_MALLOC => 1, "Use Imager's DEBUG malloc()" ]; print "Malloc debugging enabled\n"; diff --git a/error.c b/error.c index a3f172b0..8ee422c0 100644 --- a/error.c +++ b/error.c @@ -351,6 +351,21 @@ int i_failed(int code, char const *msg) { #endif +/* +=item im_assert_fail(file, line, message) + +Called when an im_assert() assertion fails. + +=cut +*/ + +void +im_assert_fail(char const *file, int line, char const *message) { + fprintf(stderr, "Assertion failed line %d file %s: %s\n", + line, file, message); + exit(EXIT_FAILURE); +} + /* =back diff --git a/image.c b/image.c index d1aa2082..e6d5345d 100644 --- a/image.c +++ b/image.c @@ -1002,13 +1002,14 @@ i_scale_nn(i_img *im, float scx, float scy) { nxsize = (int) ((float) im->xsize * scx); if (nxsize < 1) { nxsize = 1; - scx = 1 / im->xsize; + scx = 1.0 / im->xsize; } nysize = (int) ((float) im->ysize * scy); if (nysize < 1) { nysize = 1; - scy = 1 / im->ysize; + scy = 1.0 / im->ysize; } + im_assert(scx != 0 && scy != 0); new_img=i_img_empty_ch(NULL,nxsize,nysize,im->channels); diff --git a/imageri.h b/imageri.h index 613bd5d1..7cc3e9d4 100644 --- a/imageri.h +++ b/imageri.h @@ -97,4 +97,15 @@ extern void i_int_hlines_fill_fill(i_img *im, i_int_hlines *hlines, i_fill_t *fi #define I_LIMIT_8(x) ((x) < 0 ? 0 : (x) > 255 ? 255 : (x)) #define I_LIMIT_DOUBLE(x) ((x) < 0.0 ? 0.0 : (x) > 1.0 ? 1.0 : (x)) +#define I_STRING(x) #x + +/* I considered using assert.h here, but perl does it's own thing with + assert() and the NDEBUG test is opposite to the direction I prefer */ +#ifdef IM_ASSERT +extern void im_assert_fail(char const *, int, char const *); +#define im_assert(x) ((x) ? (void)(0) : im_assert_fail(__FILE__, __LINE__, I_STRING(x))) +#else +#define im_assert(x) (void)(0) +#endif + #endif