Skip to content

Commit

Permalink
- an integer division meant that preview scaling to below 1 pixel
Browse files Browse the repository at this point in the history
   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
Tony Cook committed Sep 17, 2009
1 parent 2d0c4c9 commit b3afeed
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -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
===========

Expand Down
12 changes: 11 additions & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";
Expand All @@ -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";
Expand Down
15 changes: 15 additions & 0 deletions error.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions image.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions imageri.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.