SAC program fails to read PGM array data
|
|
Bugzilla Link |
917 |
Created on |
Feb 22, 2012 12:22 |
Resolution |
FIXED |
Resolved on |
Mar 04, 2012 17:14 |
Version |
1.00beta |
OS |
Linux |
Architecture |
PC |
Extended Description
The following code tests the SAC PGM library.
When run on this small test PGM file:
P2
2 2
255
0 255
0 255
it crashes with this message:
Reading pat2_2x2.pgm ...
Writing /dev/null as binary ...
Writing /dev/null as text ...
*** SAC runtime error
*** Memory access violation on reading from array SACp_pinl_2316_ret
*** with size 0 at index position 0 !
use StdIO: { printf };
use RuntimeError: { error };
use CommandLine: { argc, argv };
use SysErr: { fail };
use PGM: { readPGM, printPGM };
import Grey: all;
import ScalarArith: all;
import Array: all;
use ArrayIO: { print };
int main()
{
if (argc() < 2) {
error(1, "Need at least one file arg");
}
for (i = 1; i < argc(); ++i) {
name = argv(i);
printf("Reading %s ...\n", name);
g = readPGM(name);
printf("Writing /dev/null as binary ...\n");
printPGM(g, "/dev/null", true);
printf("Writing /dev/null as text ...\n");
printPGM(g, "/dev/null", false);
shp = Grey::shape(g);
// print(shp);
w = shp[0];
h = shp[1];
min = maxint();
max = minint();
for (y = 0; y < h; ++y) {
for (x = 0; x < w; ++x) {
if (min > (:int) g[y,x]) {
min = (:int) g[y,x];
}
if (max < (:int) g[y,x]) {
max = (:int) g[y,x];
}
}
}
printf("Minimum is %d, maximum is %d\n", min, max);
}
return 0;
}
I