Posted by
dscho on
Feb 13, 2009; 2:10am
URL: http://imagej.273.s1.nabble.com/Tiny-PGM-file-reading-bug-and-proposed-fix-tp3693712p3693713.html
Hi Harry,
sorry it took me so long, my inbox is only now starting to look better...
On Thu, 31 Jul 2008, Harry Parker wrote:
> I get Java exceptions when trying to open tiny PGM test image files.
> This is with the latest ImageJ, v. 1.41i.
How does this look?
-- snipsnap --
[PATCH] PGM_Reader: fix division by zero
When reading .pgm files which have a size smaller than 20, there was
a division by zero.
Noticed by Harry Parker.
Signed-off-by: Johannes Schindelin <
[hidden email]>
---
ij/plugin/PGM_Reader.java | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/ij/plugin/PGM_Reader.java b/ij/plugin/PGM_Reader.java
index c0caee7..378c6f7 100644
--- a/ij/plugin/PGM_Reader.java
+++ b/ij/plugin/PGM_Reader.java
@@ -259,7 +259,7 @@ public class PGM_Reader extends ImagePlus implements PlugIn {
while (tok.nextToken() != tok.TT_EOF) {
if (tok.ttype == tok.TT_NUMBER) {
pixels[i++] = (byte) (((int) tok.nval) & 255);
- if (i % inc == 0)
+ if (inc != 0 && (i % inc == 0))
IJ.showProgress(0.5 + ((double) i / size) / 2.0);
}
}
@@ -293,7 +293,7 @@ public class PGM_Reader extends ImagePlus implements PlugIn {
while (tok.nextToken() != tok.TT_EOF) {
if (tok.ttype == tok.TT_NUMBER) {
pixels[i++] = (short) (((int) tok.nval) & 65535);
- if (i % inc == 0)
+ if (int != 0 && (i % inc == 0))
IJ.showProgress(0.5 + ((double) i / size) / 2.0);
}
}
--
1.6.2.rc0.344.gecd284