]> git.imager.perl.org - imager.git/commitdiff
- an integer division meant that preview scaling to below 1 pixel
authorTony Cook <tony@develop=help.com>
Thu, 17 Sep 2009 12:26:22 +0000 (12:26 +0000)
committerTony Cook <tony@develop=help.com>
Thu, 17 Sep 2009 12:26:22 +0000 (12:26 +0000)
   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.

Changes
Makefile.PL
error.c
image.c
imageri.h

diff --git a/Changes b/Changes
index fe2db308ce83779814fc18261a2c5610a72c8976..0e8d74cb1a2a5ec3171b321cc5170855e0d8d92d 100644 (file)
--- 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
 ===========
 
index c05d5b3885079b068e3450c541efdc278f146f65..291a58c5262570ccec2b5bd68cecc59c6efd83ec 100644 (file)
@@ -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 a3f172b03d4a2d5f0cf1f8225e9a8007d0a80cd6..8ee422c0df24146419a031caae195124aeef1b2a 100644 (file)
--- 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 d1aa2082025b140ac33ae86a44ca54eb355140ec..e6d5345d529908d75e9d05b4b7a3e337cc68c8c9 100644 (file)
--- 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);
   
index 613bd5d120327cde9af740bebc7f872d2d25915c..7cc3e9d4ce56d69c344ca5bd454cddb2f74be45b 100644 (file)
--- 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