Index: /trunk/psLib/src/mathtypes/psVector.c
===================================================================
--- /trunk/psLib/src/mathtypes/psVector.c	(revision 7043)
+++ /trunk/psLib/src/mathtypes/psVector.c	(revision 7044)
@@ -9,6 +9,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.69 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-05-02 21:48:55 $
+*  @version $Revision: 1.70 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-05-02 23:02:29 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -206,4 +206,8 @@
 
     output = psVectorRecycle(output, nElements, type);
+    if (nElements == 0) {
+        psWarning("Warning: psVector was copied with 0 elements!\n");
+        return output;
+    }
     output->n = nElements;
 
@@ -333,5 +337,5 @@
 case PS_TYPE_##NAME: { \
     ps##NAME temp; \
-    ps##NAME *value = out->data.NAME; \
+    ps##NAME *value = outVector->data.NAME; \
     for (;;) { \
         if (l > 0) { \
@@ -342,5 +346,5 @@
             if (--ir == 0) { \
                 value[0] = temp; \
-                return out; \
+                return outVector; \
             } \
         } \
@@ -372,12 +376,25 @@
     }
 
-    psVector *out = psVectorCopy(outVector, inVector, inVector->type.type); // Copy to sort in place
-    long N = out->n;                    // Number of elements
+    //    printf("\nbefore psVectorCopy\n");
+    //    psVector *out = psVectorCopy(outVector, inVector, inVector->type.type); // Copy to sort in place
+    outVector = psVectorCopy(outVector, inVector, inVector->type.type);
+    //    printf("\nafter psVectorCopy\n");
+    if (outVector == NULL) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, true,
+                "Error in psVectorSort:  psVectorCopy returned NULL vector!\n");
+        return NULL;
+    }
+    long N = outVector->n;                    // Number of elements
     if (N < 2) {
-        return out;
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "Error in psVectorSort:  Vector has less than 2 data entries!\n");
+        psFree(outVector);
+        //        psFree(outVector);
+        //        outVector = NULL;
+        return NULL;
     }
     long l = N >> 1;
     long ir = N - 1;
-    switch (out->type.type) {
+    switch (outVector->type.type) {
         PSVECTOR_SORT_CASE(U8);
         PSVECTOR_SORT_CASE(U16);
@@ -397,5 +414,5 @@
         return NULL;
     }
-    return out;
+    return outVector;
 }
 
