IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6551


Ignore:
Timestamp:
Mar 8, 2006, 4:42:56 PM (20 years ago)
Author:
Paul Price
Message:

Set array components to NULL on alloc, realloc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psLib/src/types/psArray.c

    r5530 r6551  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-11-16 23:06:35 $
     11 *  @version $Revision: 1.40.10.1 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2006-03-09 02:42:56 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6868    // Create vector data array
    6969    psArr->data = psAlloc(nalloc * sizeof(psPtr));
     70    // Set everything to NULL
     71    memset(psArr->data, (int)NULL, nalloc*sizeof(psPtr));
    7072
    7173    return psArr;
     
    7880        psError(PS_ERR_BAD_PARAMETER_NULL,true,PS_ERRORTEXT_psArray_REALLOC_NULL);
    7981        return NULL;
    80     } else if (in->nalloc != nalloc) {     // No need to realloc to same size
     82    }
     83    if (in->nalloc != nalloc) {         // No need to realloc to same size
    8184        if (nalloc < in->n) {
    8285            for (psS32 i = nalloc; i < in->n; i++) {      // For reduction in vector size
     
    8790        // Realloc after decrementation to avoid accessing freed array elements
    8891        in->data = psRealloc(in->data, nalloc * sizeof(psPtr));
     92        if (nalloc > in->nalloc) {
     93            // Expanding the array: set new pointers to NULL
     94            memset(&in->data[in->nalloc], (int)NULL, nalloc - in->nalloc);
     95        }
    8996        P_PSARRAY_SET_NALLOC(in,nalloc);
    9097    }
Note: See TracChangeset for help on using the changeset viewer.