IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7044


Ignore:
Timestamp:
May 2, 2006, 1:02:29 PM (20 years ago)
Author:
drobbin
Message:

Edited psVectorCopy and psVectorSort. Added error handling for NULL vectors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/mathtypes/psVector.c

    r7042 r7044  
    99*  @author Robert DeSonia, MHPCC
    1010*
    11 *  @version $Revision: 1.69 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2006-05-02 21:48:55 $
     11*  @version $Revision: 1.70 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2006-05-02 23:02:29 $
    1313*
    1414*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    206206
    207207    output = psVectorRecycle(output, nElements, type);
     208    if (nElements == 0) {
     209        psWarning("Warning: psVector was copied with 0 elements!\n");
     210        return output;
     211    }
    208212    output->n = nElements;
    209213
     
    333337case PS_TYPE_##NAME: { \
    334338    ps##NAME temp; \
    335     ps##NAME *value = out->data.NAME; \
     339    ps##NAME *value = outVector->data.NAME; \
    336340    for (;;) { \
    337341        if (l > 0) { \
     
    342346            if (--ir == 0) { \
    343347                value[0] = temp; \
    344                 return out; \
     348                return outVector; \
    345349            } \
    346350        } \
     
    372376    }
    373377
    374     psVector *out = psVectorCopy(outVector, inVector, inVector->type.type); // Copy to sort in place
    375     long N = out->n;                    // Number of elements
     378    //    printf("\nbefore psVectorCopy\n");
     379    //    psVector *out = psVectorCopy(outVector, inVector, inVector->type.type); // Copy to sort in place
     380    outVector = psVectorCopy(outVector, inVector, inVector->type.type);
     381    //    printf("\nafter psVectorCopy\n");
     382    if (outVector == NULL) {
     383        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     384                "Error in psVectorSort:  psVectorCopy returned NULL vector!\n");
     385        return NULL;
     386    }
     387    long N = outVector->n;                    // Number of elements
    376388    if (N < 2) {
    377         return out;
     389        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     390                "Error in psVectorSort:  Vector has less than 2 data entries!\n");
     391        psFree(outVector);
     392        //        psFree(outVector);
     393        //        outVector = NULL;
     394        return NULL;
    378395    }
    379396    long l = N >> 1;
    380397    long ir = N - 1;
    381     switch (out->type.type) {
     398    switch (outVector->type.type) {
    382399        PSVECTOR_SORT_CASE(U8);
    383400        PSVECTOR_SORT_CASE(U16);
     
    397414        return NULL;
    398415    }
    399     return out;
     416    return outVector;
    400417}
    401418
Note: See TracChangeset for help on using the changeset viewer.