[Proj] pj_malloc() inits P->es as junk memory
David Turover
dturover at student.santarosa.edu
Fri Aug 14 16:40:51 EST 2009
I had semi-random failures in my modified pj_goode (which uses pj_gn_sinu
and pj_moll) where the results from sinu would come back as inf, inf. In
these cases, sinu was initialized to use its ellipsoid functions instead
of its spherical functions.
It seems P->es was not initialized in PJ_gn_sinu.c ENTRY1(sinu, en) where
P->es is checked to see whether the spherical or ellipsoid functions should
be used. Every so often, malloc would put memory with nonzero data in P->es.
This can be fixed by replacing malloc() with calloc() at pj_alloc.c line 20:
// void *res = malloc(size);
void *res = (void*) calloc(size, sizeof(void));
The random inf problem should happen with the official pj_goode as well.
I haven't tested it, but I didn't modify it enough that it should matter
to this issue.
Note: pj_gn_sinu's setup() sets P->es to zero, but that function is not
called until after P->es is first tested in ENTRY1. It can't be moved
before the test because that would wipe out any intentional setting of
P->es to a nonzero value from an outside function that calls ENTRY1 on an
already allocated sinu object.
- David T.
More information about the Proj
mailing list