Permalink
Browse files

- 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.
  • Loading branch information...
1 parent 2d0c4c9 commit b3afeed5d907587a0ba5b491f2f5420375edd185 Tony Cook committed Sep 17, 2009
Showing with 47 additions and 3 deletions.
  1. +7 −0 Changes
  2. +11 −1 Makefile.PL
  3. +15 −0 error.c
  4. +3 −2 image.c
  5. +11 −0 imageri.h
View
@@ -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
===========
View
@@ -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";
View
15 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
View
@@ -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);
View
@@ -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

0 comments on commit b3afeed

Please sign in to comment.