Problem: poor 2D array allocation and deallocation that can cause problems on some systems when using proj -L option or library usage of approximation procedures. Solution: cd ?/PROJ.4/src patch /* basic support procedures */ --- 1,6 ---- /* convert bivariate w Chebyshev series to w Power series */ #ifndef lint ! static const char SCCSID[]="@(#)bch2bps.c 4.5 94/03/22 GIE REL"; #endif #include /* basic support procedures */ *************** *** 67,74 **** UV *sv, **dd; int j, k; ! dd = (UV **)vector2(nu-1, nv-1, sizeof(UV)); ! sv = (UV *)vector1(nv-1, sizeof(UV)); bclear(d, nu, nv); bclear(dd, nu, nv); bmove(d[0], c[nu-1], nv); --- 67,74 ---- UV *sv, **dd; int j, k; ! dd = (UV **)vector2(nu, nv, sizeof(UV)); ! sv = (UV *)vector1(nv, sizeof(UV)); bclear(d, nu, nv); bclear(dd, nu, nv); bmove(d[0], c[nu-1], nv); *************** *** 85,91 **** for (j = nu-1; j >= 1; --j) subop(d[j], d[j-1], dd[j], nv); submop(d[0], .5, c[0], dd[0], nv); ! pj_dalloc(dd); pj_dalloc(sv); } static void /* row adjust for range -1 to 1 to a to b */ --- 85,91 ---- for (j = nu-1; j >= 1; --j) subop(d[j], d[j-1], dd[j], nv); submop(d[0], .5, c[0], dd[0], nv); ! freev2(dd, nu); pj_dalloc(sv); } static void /* row adjust for range -1 to 1 to a to b */ *************** *** 138,143 **** /* do columns to power series */ cols(d, c, nu, nv); colshft(a.u, b.u, c, nu, nv); ! pj_dalloc(d); return 1; } --- 138,143 ---- /* do columns to power series */ cols(d, c, nu, nv); colshft(a.u, b.u, c, nu, nv); ! freev2(d, nu); return 1; } *** bchgen.c.orig Tue Mar 22 11:50:06 1994 --- bchgen.c Tue Mar 22 11:50:06 1994 *************** *** 1,6 **** /* generate double bivariate Chebychev polynomial */ #ifndef lint ! static const char SCCSID[]="@(#)bchgen.c 4.4 93/06/12 GIE REL"; #endif #include int --- 1,6 ---- /* generate double bivariate Chebychev polynomial */ #ifndef lint ! static const char SCCSID[]="@(#)bchgen.c 4.5 94/03/22 GIE REL"; #endif #include int *** mk_cheby.c.orig Tue Mar 22 11:50:06 1994 --- mk_cheby.c Tue Mar 22 11:50:07 1994 *************** *** 1,5 **** #ifndef lint ! static const char SCCSID[]="@(#)mk_cheby.c 4.4 93/06/12 GIE REL"; #endif #include static void /* sum coefficients less than res */ --- 1,5 ---- #ifndef lint ! static const char SCCSID[]="@(#)mk_cheby.c 4.5 94/03/22 GIE REL"; #endif #include static void /* sum coefficients less than res */ *************** *** 43,50 **** UV **w; double cutres; ! if (!(w = (UV **)vector2(nu-1, nv-1, sizeof(UV))) || ! !(ncu = (int *)vector1(nu + nv - 2, sizeof(int)))) return 0; ncv = ncu + nu; if (!bchgen(a, b, nu, nv, w, func)) { --- 43,50 ---- UV **w; double cutres; ! if (!(w = (UV **)vector2(nu, nv, sizeof(UV))) || ! !(ncu = (int *)vector1(nu + nv, sizeof(int)))) return 0; ncv = ncu + nu; if (!bchgen(a, b, nu, nv, w, func)) { *************** *** 147,153 **** } goto gohome; error: ! if (T) { /* pj_dalloc.g up possible allocations */ for (i = 0; i <= T->mu; ++i) if (T->cu[i].c) pj_dalloc(T->cu[i].c); --- 147,153 ---- } goto gohome; error: ! if (T) { /* pj_dalloc up possible allocations */ for (i = 0; i <= T->mu; ++i) if (T->cu[i].c) pj_dalloc(T->cu[i].c); *************** *** 158,164 **** } T = 0; gohome: ! pj_dalloc(w); pj_dalloc(ncu); return T; } --- 158,164 ---- } T = 0; gohome: ! freev2(w, nu); pj_dalloc(ncu); return T; } *** vector1.c.orig Tue Mar 22 11:50:07 1994 --- vector1.c Tue Mar 22 11:50:07 1994 *************** *** 1,29 **** /* make storage for one and two dimensional matricies */ #ifndef lint ! static const char SCCSID[]="@(#)vector1.c 4.3 93/06/12 GIE REL"; #endif #include #include void * /* one dimension array */ ! vector1(int hi, int size) { return((void *)pj_malloc(size * (hi + 1))); } void ** /* two dimension array */ ! vector2(int uhi, int vhi, int size) { ! char **s; ! int nu, nv; ! nu = uhi + 1; ! nv = vhi + 1; ! if (s = (char **)pj_malloc(sizeof(void *) * nu + size * nv * nu)) { ! char *t; ! char **r; ! int i; ! t = (char *)(s + nu); ! r = s; ! for (i = 0; i < nu; ++i) { ! *r++ = t; ! t += nv * size; ! } } ! return ((void **)s); } --- 1,32 ---- /* make storage for one and two dimensional matricies */ #ifndef lint ! static const char SCCSID[]="@(#)vector1.c 4.4 94/03/22 GIE REL"; #endif #include #include void * /* one dimension array */ ! vector1(int nvals, int size) { return((void *)pj_malloc(size * nvals)); } ! void /* free 2D array */ ! freev2(void **v, int nrows) { ! if (v) { ! for (v += nrows; nrows > 0; --nrows) ! pj_dalloc(*--v); ! pj_dalloc(v); ! } ! } void ** /* two dimension array */ ! vector2(int nrows, int ncols, int size) { ! void **s; ! if (s = (void **)pj_malloc(sizeof(void *) * nrows)) { ! int rsize, i; ! rsize = size * ncols; ! for (i = 0; i < nrows; ++i) ! if (!(s[i] = pj_malloc(rsize))) { ! freev2(s, i); ! return (void **)0; ! } } ! return s; }