pj_malloc() inits P->es as junk memory

2 messages Options
Embed this post
Permalink
David Turover

pj_malloc() inits P->es as junk memory

Reply Threaded More More options
Print post
Permalink
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.
_______________________________________________
Proj mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/proj
Gerald I. Evenden

Re: pj_malloc() inits P->es as junk memory

Reply Threaded More More options
Print post
Permalink
Three comments:

1. I do not agree with what you are doing because segmenting of Goode is *not*
a standard

2. It is a graphic operation very easily handled by external scripts.

3. You are using very dated code and a quick check of current proj_init shows
that es and a host of other variables are initialized *very* early in the
structure initialization---expecially when compared with the ancient pj
stuff.  Also pj_alloc is not used anymore and malloc is directly called where
applicable.

On Friday 14 August 2009 5:40:51 pm David Turover wrote:

> 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.
> _______________________________________________
> Proj mailing list
> [hidden email]
> http://lists.maptools.org/mailman/listinfo/proj



--
The whole religious complexion of the modern world is due
to the absence from Jerusalem of a lunatic asylum.
-- Havelock Ellis (1859-1939) British psychologist
_______________________________________________
Proj mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/proj