Index: /trunk/psLib/src/types/psList.c
===================================================================
--- /trunk/psLib/src/types/psList.c	(revision 9085)
+++ /trunk/psLib/src/types/psList.c	(revision 9086)
@@ -6,6 +6,6 @@
  *  @author Robert Daniel DeSonia, MHPCC
  *
- *  @version $Revision: 1.52 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-08-26 04:34:28 $
+ *  @version $Revision: 1.53 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-02 06:05:53 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -33,21 +33,20 @@
 static void listFree(psList* list)
 {
-    if (list == NULL) {
-        return;
-    }
-
-    // remove the associated iterators -- any references are invalid once psList is freed.
-    psArray* iterators = list->iterators;
-    // ONLY orphan the iterators if the list iterators are about to be destroyed
-    // a case where this is not the case is in psListSort.
-    if (psMemGetRefCounter(iterators)  < 2) {
-        for (int i = 0; i < iterators->n; i++) {
-            // orphan iterators first to avoid any callbacks to dying list
-            ((psListIterator*)iterators->data[i])->list = NULL;
-            // remove all external references
-            psMemSetRefCounter(iterators->data[i], 1);
-        }
-    }
-    psFree(iterators);
+    if (list->iterators != NULL) {
+
+        // remove the associated iterators -- any references are invalid once psList is freed.
+        psArray* iterators = list->iterators;
+        // ONLY orphan the iterators if the list iterators are about to be destroyed
+        // a case where this is not the case is in psListSort.
+        if (psMemGetRefCounter(iterators)  < 2) {
+            for (int i = 0; i < iterators->n; i++) {
+                // orphan iterators first to avoid any callbacks to dying list
+                ((psListIterator*)iterators->data[i])->list = NULL;
+                // remove all external references
+                psMemSetRefCounter(iterators->data[i], 1);
+            }
+        }
+        psFree(iterators);
+    }
 
     for (psListElem* ptr = list->head; ptr != NULL;) {
@@ -63,8 +62,4 @@
 static void listIteratorFree(psListIterator* iter)
 {
-    if (iter == NULL) {
-        return;
-    }
-
     // remove this iterator from the parent list
     if (iter->list != NULL) {
@@ -151,6 +146,13 @@
 }
 
-psListIterator* psListIteratorAlloc(psList* list, long location, bool mutable)
-{
+psListIterator* psListIteratorAlloc(psList* list,
+                                    long location,
+                                    bool mutable)
+{
+    if (list == NULL) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, true,
+                _("Specified list is NULL."));
+        return false;
+    }
     psListIterator* iter = psAlloc(sizeof(psListIterator));
 
@@ -180,5 +182,5 @@
                        long location)
 {
-    if (iterator == NULL) {
+    if (iterator == NULL || iterator->list == NULL) {
         return false;
     }
@@ -214,11 +216,13 @@
     int index = iterator->index;
     if (cursor == NULL) {      // set the cursor to the head if it is NULL
-        if (location > list->n/2) { // closer to tail or head?
-            cursor = list->tail;
-            index = list->n - 1;
-        } else {
-            cursor = list->head;
-            index = 0;
-        }
+        //XXX: if location can't be >= n, it def. can't be greater than n/2.
+        /*        if (location > list->n/2) { // closer to tail or head?
+                    cursor = list->tail;
+                    index = list->n - 1;
+                } else {
+        */
+        cursor = list->head;
+        index = 0;
+        //        }
     }
 
@@ -243,5 +247,7 @@
 }
 
-bool psListAdd(psList* list, long location, psPtr data)
+bool psListAdd(psList* list,
+               long location,
+               psPtr data)
 {
 
@@ -279,5 +285,6 @@
 }
 
-bool psListAddAfter(psListIterator* iterator, void* data)
+bool psListAddAfter(psListIterator* iterator,
+                    void* data)
 {
     if (data == NULL) {
@@ -332,8 +339,10 @@
     list->n++;
 
-    if (cursor == list->tail) {
-        list->tail = elem;
-    }
-
+    //XXX: The following is unreachable.  cursor can't == list->tail unless cursor->next == NULL.
+    // in which case list->tail will be set to elem.  (list->tail = elem;)
+    /*    if (cursor == list->tail) {
+            list->tail = elem;
+        }
+    */
     psArray* iterators = list->iterators;
     int index = iterator->index;
@@ -348,5 +357,6 @@
 }
 
-bool psListAddBefore(psListIterator* iterator, void* data)
+bool psListAddBefore(psListIterator* iterator,
+                     void* data)
 {
     if (data == NULL) {
@@ -401,8 +411,10 @@
     list->n++;
 
-    if (cursor == list->head) {
-        list->head = elem;
-    }
-
+    //XXX: The following is unreachable.  cursor can't == list->head unless cursor->prev == NULL.
+    // in which case list->head will be set to elem.  (list->tail = elem;)
+    /*   if (cursor == list->head) {
+            list->head = elem;
+        }
+    */
     psArray* iterators = list->iterators;
     int index = iterator->index;
@@ -469,5 +481,6 @@
 }
 
-psPtr psListGet(psList* list, long location)
+psPtr psListGet(psList* list,
+                long location)
 {
     if (list == NULL) {
@@ -478,4 +491,6 @@
 
     if (list->head == NULL) { // list empty?
+        psError(PS_ERR_BAD_PARAMETER_NULL, true,
+                _("Specified psList reference is empty."));
         return NULL;
     }
@@ -527,5 +542,6 @@
     }
     if ((iterator->cursor == NULL) && (!iterator->offEnd))  {
-        psLogMsg(__func__,PS_LOG_WARN,"Attempt to get previous with itertator cursor NULL and offEnd false");
+        psLogMsg(__func__,PS_LOG_WARN,
+                 "Attempt to get previous element with NULL iterator cursor and offEnd=false");
         return NULL;
     }
@@ -594,5 +610,6 @@
 }
 
-psList* psListSort(psList* list, psComparePtrFunc func)
+psList* psListSort(psList* list,
+                   psComparePtrFunc func)
 {
     psArray* arr;
Index: /trunk/psLib/src/types/psList.h
===================================================================
--- /trunk/psLib/src/types/psList.h	(revision 9085)
+++ /trunk/psLib/src/types/psList.h	(revision 9086)
@@ -7,6 +7,6 @@
  *  @ingroup LinkedList
  *
- *  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-02 23:04:22 $
+ *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-02 06:05:53 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -139,10 +139,10 @@
 );
 
-/** Adds an data item to a psList at position just before the list position given
+/** Adds a data item to a psList at position just before the list position given
  *
  *  @return bool        TRUE if item was successfully added, otherwise FALSE.
  */
 bool psListAddBefore(
-    psListIterator* iterator,              ///< list position to add item to
+    psListIterator* iterator,          ///< list position to add item to
     psPtr data                         ///< data item to add.  If NULL, list is not modified.
 );
@@ -154,5 +154,5 @@
 bool psListRemove(
     psList* list,                      ///< list to remove element from
-    long location                     ///< index of item
+    long location                      ///< index of item
 );
 
@@ -175,5 +175,5 @@
 psPtr psListGet(
     psList* list,                      ///< list to retrieve element from
-    long location                     ///< index number, PS_LIST_HEAD, or PS_LIST_TAIL
+    long location                      ///< index number, PS_LIST_HEAD, or PS_LIST_TAIL
 );
 
@@ -202,5 +202,5 @@
  */
 psArray* psListToArray(
-    const psList* list                      ///< List to convert
+    const psList* list                 ///< List to convert
 );
 
@@ -211,5 +211,5 @@
  */
 psList* psArrayToList(
-    const psArray* array                       ///< vector to convert
+    const psArray* array               ///< vector to convert
 );
 
