--- ray/src/common/interp2d.c 2013/02/16 00:41:12 2.13 +++ ray/src/common/interp2d.c 2021/03/11 01:58:59 2.16 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: interp2d.c,v 2.13 2013/02/16 00:41:12 greg Exp $"; +static const char RCSid[] = "$Id: interp2d.c,v 2.16 2021/03/11 01:58:59 greg Exp $"; #endif /* * General interpolation method for unstructured values on 2-D plane. @@ -70,6 +70,7 @@ interp2_alloc(int nsamps) nip->ns = nsamps; nip->dmin = 1; /* default minimum diameter */ nip->smf = NI2DSMF; /* default smoothing factor */ + nip->c_data = NULL; nip->da = NULL; /* caller must assign spt[] array */ return(nip); @@ -79,6 +80,8 @@ interp2_alloc(int nsamps) INTERP2 * interp2_realloc(INTERP2 *ip, int nsamps) { + INTERP2 *old_ip = ip; + if (ip == NULL) return(interp2_alloc(nsamps)); if (nsamps <= 1) { @@ -92,8 +95,12 @@ interp2_realloc(INTERP2 *ip, int nsamps) ip->da = NULL; } ip = (INTERP2 *)realloc(ip, sizeof(INTERP2)+sizeof(float)*2*(nsamps-1)); - if (ip == NULL) - return(NULL); + if (ip == NULL) { + if (nsamps <= ip->ns) + ip = old_ip; + else + return(NULL); + } ip->ns = nsamps; return(ip); } @@ -266,7 +273,7 @@ sort_samples(SAMPORD *sord, const INTERP2 *ip, double sord[i].si = i; sord[i].dm = cosd*ip->spt[i][0] + sind*ip->spt[i][1]; } - qsort(sord, ip->ns, sizeof(SAMPORD), &cmp_spos); + qsort(sord, ip->ns, sizeof(SAMPORD), cmp_spos); } /* (Re)compute anisotropic basis function interpolant (normally automatic) */